A Poor Man's API
blog.frankel.ch
blog.frankel.ch
Does anyone else miss the old days of just editing your site's code and adding new columns to your MYSQL database while people were surfing your website? That was fun.
Tip: Another way to turn your DB into an API is to just connect to it and then write SQL queries.
Other than the easy money, nah, don't miss the old days that much.
Having to use Reflector to decompile a core .NET library to figure out wtf it was doing because MSDN was inadequate, and the source was very much not open.
PHP 4 code bases that heavily leaned on dangerous globals.
J2EE.
Ah, the "good" ol days.
I remember reading "High-Performance MySQL" in mid-200s. It was a real eye-opener: all the things you needed from a DB where somewhat randomly available across the different storage mechanisms, but not in any consistent form.
Something like: Oh, you need query optimisation? Use one. You need constraints? Use the other. you need fast indexes? Use the first one again. And so on.
> Ah, the "good" ol days.
You'll pry my nostalgia from my cold dead hands!
I am astounded to learn MySQL predates so much technological advancement! >.<
> Howto: Upload "api.php" to your webserver, configure it to connect to your database, have an instant full-featured REST API.
It is nominally a "headless CMS", but it's so close to the SQL that I think of it more like API in a box.
I can assure you you don't need to do that. And most people don't.
It's perfectly possible to create a useful API without adhering to the REST principles.
[Edit, having read the rest of the article]: Case in point, this very PostgREST tool promoted in the article appears very useful, while not thinking about the REST principles.
EDIT: And the corollary of above is that most people when saying REST actually mean HTTP with correct method use.
If not, then is there a good source on what you mean by REST and HATEOAS?
REST is defined by four interface constraints: identification of resources; manipulation of resources through representations; self-descriptive messages; and, hypermedia as the engine of application state.
What does "REST" mean to you?
To me, like most people, REST means an http-based API where we use GET, POST, PUT, DELETE etc. to interact with resources. This in full understanding that under a literal interpretation of the enlightened one's (Roy Fielding's) utterances, REST mandates HATEOAS, meaning that there are only a few true REST APIs to be seen in the wild.
I also usually use the term RESTful, this seems to be a somewhat widely accepted middleground.
Sort of like how youtube is filled with videos about "damascus steel" which is nothing more than steel of random, irrelevant composition with certain visual pattern akin to actual damascus steel. But again, good luck finding a video about the real deal.
Same can be said about ASMR, and many other misappropriated terms people throw around for clickbait.
Rant over.
I don't think service developers take HATEOAS super-seriously. From what I've seen, returning resources with a URI rather than an identifier is about all many services do to be HATEOAS-ish. Clients are coupled to the server, but that's often okay.
And if you go with HAL or JSON-LD, you have to use a specific clients for those formats, so not universal anyway.
I tend to agree with "HATEOAS is for Humans"[1], HATEOAS makes sense when interacting with HTML.
[1]: https://intercoolerjs.org/2016/05/08/hatoeas-is-for-humans.h...
It would be hard not to make that client behave like a browser from the user's point of view.
Example: Retrieve JSON for https://fivethirtyeight.datasettes.com/polls/president_prima... simply with https://covid-19.datasettes.com/covid/ny_times_us_counties.j... (I added a filter for Texas)
The schema is ad-hoc and requires a human to interpret it. Link relations (at the bottom) are expressed the wrong way: a machine could understand the "next" or "license" relations, but not an arbitrary "next_url" or "license_url" JSON key.
Recommendation: adopt relevant IETF/IANA standards and reformulate the response to take advantage of them.
Why? What is it about postgrest which makes it unsuitable for "real" usage? The author doesn't mention it.
1. Side effects: Want to send an email when something happens
2. conditional permissions: Need access to data under certain circumstances not modelled by the security language?
3. Subset access: Access to parts of the row / document.
4. Aggregate access: Access to eg. a count of rows you can not access.
These are usually solved using serverless functions – or an API written in code.
Personally I err to the side of just writing some code, maybe because I enjoy that part of the project. Then I might be more inclined to use no-code solutions for the frontend, where others want the freedom and flexibility.
I handle #1 with by listening to database changes then reacting as needed with a change capture / event-like system:
Which is not necessarily bad, RLS is sophisticated enough to handle all real world cases I've come across. But if it's just that I think it's more correct to say postgres already handles all of this.
Why start with an SQL database? When I start something new, I don't want to fiddle around with tables every time I change my model.
Is there a relational schemaless DB I wonder?
It’s no longer relational vs. NoSQL, you can get the best of both worlds. Assuming of course you don’t need “planetscale”.
But really, my advice for early prototyping is split in two: either keep it in memory and serialize to disk, or use SQLite.
Note that even using serialized memory constructs will require data migrations, aka schema updates.
This setup can be used to prevent the backends from being overloaded, which one can probably already do from a single host, and depending on the speed/amount of work by the backends done, not a lot of bandwidth is required to overload most systems that have a limited amount of request processing capacity.
I would argue that this is load management/shedding though, and not DDoS protection.
You can't really protect against it, you can only have enough bandwidth to handle everything.
Network engineers define it as one thing: a massive amount of abnormal traffic generated by a large number of sources (distributed) that you need adequate bandwidth to soak up without impacting normal traffic.
Software engineers define it as another thing: unwanted traffic that causes resource exhaustion and should be blocked. They're almost always thinking of DoS but refer to it as DDoS.
That's why when TFA talks about DDoS, the example immediately attached to it is rate limiting at what to me (network engineering background) seems like an absurdly low limit (1 request every 5 seconds).
Let user write their own SQL queries and meter how much time they use for billing or abuse prevention.
Databases are huge security vulnerabilities and should always have some kind of shim over them. Never expose your relational DB publicly if you want any control over it.
Or (as is the fashion recently) compile sqlite to wasm and run it in browser.
The folks created an almost full fledged Firebase replacement by clipping pieces together (similar to the article, replacing APISIX with Kong) and it allows them to iterate super fast.
Pragmatic, and nice if you're on the receiving end of it .
I find it a bit ironic that they don't support Apache2 as the web server, you know, it being an Apache project and all, instead going for Nginx or OpenResty (though admittedly they're great projects).
Even nowadays Apache2 is pretty okay: https://blog.kronis.dev/tutorials/how-and-why-to-use-apache-... (especially if you disable .htaccess for less disk I/O and use it with a single file based config)
If you're starting from scratch (as the post is, since PostgreSQL is advertised as part of the solution), then you have to manually create the DB schema. I would argue that a Node developer would find it easier to do that in Prisma, or a Django developer in Django ORM, than to do raw CREATE TABLE queries manually.
I'd want to host it for free, so Vercel and Netlify comes to my mind. But to go real poor man style, I'd use Google sheets as a backend and throw some caching layer on top of it. Firebase or one of its competitors is also a good idea to get some API up and running for free.
You're better off starting with Postgres than having to migrate from some kind of no-sql setup later.
If nobody uses it then no regrets doing it stupid fast.
More and more, developers need to add value to the business, instead of being the key holders of arcane invocations. It used to be that knowing how to use a computer was a technical skills; now it’s evolved into understanding the business.
Also, these tools can't handle certain back end logic (ie, API interactions and integrations, long running processes, etc). Which is the complex bit, anyways.
Otoh, if you aren’t sending 1 request per week to an installation, it’s really not active at all. The overheard of supporting this niche is probably too much for a company that clearly is in ruthless prioritization mode.
Free Tier includes:
compute up to 1 vCPU / 256 MB
storage up to 10 GiB
3 projects per user
Nikita, their CEO, was a guest on the Changelog[0] podcast a month or so ago. Well worth a listen, great episode.
https://community.neon.tech/t/plans-for-logical-replication/...
I'm also really excited about Neon.
My dream stack is Neon (Postgres) + ReadySet (database caching proxy) + Supabase.
Personally I'm more interested in vanilla PostgREST than Supabase's implementation of it, or their realtime implementation. It seems really cool but I'm not 100% sold on their ability to evaluate complex RLS rules, which is an important one for me.
ReadySet looks cool, I'll check it out. Thanks!
I haven't used their role based stuff but it looks pretty good.
You don’t need to be sold on our ability - all rules are run on the database itself. Supabase is just Postgres, we don’t run any forks. We run vanilla PostgREST too (behind a proxy)
I've had another brief look at that repo, and either you've clarified a few things since I last looked at it, or I didn't look at it closely enough in the first place. It makes far more sense to me now, the impersonation + re-query mechanism puts me at 100%.
Thanks for the response, I appreciate it.
[1] https://fly.io/docs/postgres/getting-started/what-you-should...
Could do other things like directus (handles the api gen), planetscale has free mysql tier or even using airtable as the db, it provides the api part.
I find Eloquent's approach to disconnect models from migrations a bit dangerous, but it could be me as I don't have much experience with Laravel. PlanetScale/Vitess doesn't support foreign keys, which is nice for distributed (planet scale, ha!) apps, but could be a problem for certain types of applications. I'd rather stick with (stock-ish) PostgreSQL.
Personally, I’d give a shout for https://api-platform.com/.
For me - using a similar system (Hasura), it's migrating things dependent on views. Feels like this should be a solved problem (database migration issue, not due to Hasura).
But I still prefer it over writing CRUD.
In practice the biggest issues with it are that the tooling is significantly behind the state of the art of mainstream dev tooling, both for working engineers and ops. It's also not built with this with style of working in mind, so you accumulate a lot of little struggles that are hard on engineering morale and confidence in the deployed system. DBAs have their own practices, but admin is a different discipline from dev and they aren't always directly compatible.
The other problem is that for most modestly sized money-making applications, the database is the single most resource-intensive and expensive necessary part of the stack. Putting a bunch of business logic in there will never help that, and query optimization is a difficult to acquire skill. You pretty much always end up with just a couple of people who can talk the query planner down off a cliff when you get into the shit.
https://postgrest.org/en/stable/ecosystem.html#client-side-l...
That's false. The responses don't even have hyperlinks.
We're still open on adding HATEOAS, I've just opened an issue for it: https://github.com/PostgREST/postgrest/issues/2579
According to Apache APISIX Slack[1] channel discussions and GitHub Issues/Discussions, most people focus on Security, Feature Rich, and Performance.
1. Security: As an Apache project, there have a lot of users and maintainers who are watching project activities, and the Security Team follows up very quickly.
2. Feature Rich: Just join the Slack channel and you will find that lots of questions are related to "features".
3. Performance: https://api7.ai/blog/apisix-kong-3-0-performance-comparison