
Show HN: A flat file CRUD API with just one PHP file - acostanza
http://acostanza.com/2018/03/31/incredibly-simple-flat-file-cms-strategy-static-websites/
======
ezekg
Curious--why are you reimplenting HTTP methods? Why not just use POST, PUT,
GET and DELETE instead of a custom method query param?

~~~
anonfunction
One reason is it's a lot easier to demo in person because you just need a
browser. I wouldn't design any serious API with query params but I can
understand the appeal.

------
smt88
"One file" is a bug, not a feature

~~~
childintime
The file has 78 lines, defines no functions, and performs and documents a well
defined single task. It is significant as a learning resource, and useful by
itself to interface a webapp to a local file-system. It is written in
idiomatic old-style PHP. There is a lot to like and it is easily digestable.
Then someone comes along and says it should be more complicated.

~~~
smt88
Short code isn't automatically more simple. For example, you put your secrets
directly in this file instead of environment vars or memory or a config file.

Then what if you want to add a Twilio library? But then the original author
updates the single file, and you want to pull the changes? Very complicated.

Every good software project is concerned with maintenance, not writing the
fewest lines or having a single file.

Also, as someone who has written PHP for 20 years, I don't know what
"idiomatic, old-style PHP" could mean other than "bad code".

~~~
acostanza
The entire reason I made this is because I wanted to do one really simple
thing: store the names of shows in a file that I could then resolve against
the TvMaze API so I could track shows with minimal effort. I figured maybe
other people would be interested in that the approach is extremely simple,
which is the whole point.

Twilio library? That defeats the entire purpose of this, which is to allow
simple CRUD operations on a JSON file to resolve against using a React/Angular
style SPA. This is not intended for more complex web applications. Also,
further this is simply example code, not something I am planning on updating
in any way, because it served the purpose for what I needed.

I actually have made an SMS Marketing App and for that I used Python (Flask),
PostgreSQL, Angular 4, and Docker with nginx to bring it all together.

I specifically say in my blog post that this isn't intended for teams or
anything more complex than flat file CRUD. This would blow up really quickly
and be a nightmare to work with as a team - there isn't even any sort of
validation.

The truth is, most of the time I write APIs using either Java 8,
Express/NodeJS in TypeScript, or Python with Flask with a persistence layer
like PostgreSQL all backed by Docker. I felt like that was huge overkill for
storing just the names of shows, and I didn't want to have to store this on a
VPS with a reverse proxy... I figured one PHP file was really all I needed for
the CRUD operations.

