from Hacker News

Ask HN: Entire API and DB generator from model definition

by dpix on 8/14/19, 9:03 PM with 5 comments

I've recently got back into some backend development after being more front end focused for sometime. At the current company I am at they are quite invested in using JSONAPI spec (which I actually think is great) for their microservice APIs. I've realised that a lot of these APIs simply become REST interfaces over the database with resources mapping 1:1 with the db models.

Our current process for building these out is to build a swagger definition with a mock service backend in js to unblock upstream clients like web and mobile. From there we go an implement the real API in python/flask with postgres.

It got me thinking that probably 80-90% of all the code written for the real API is boilerplate setting up models, db migrations, routes, controllers, authentication etc.

I am imagining that a fair bit of this could be automated, all you really need is a modal definition, and you could generate all of the above, abstracting all that away from the engineer. Providing hooks for inserts and updates would allow for custom business logic to slot in, and would be all the real code engineers would need to write.

What else am I missing that backend developers would want from a framework (or managed service) like this?

  • by xq3000 on 8/15/19, 12:10 AM

    I would say that’s a valid insight and most Line Of business (LOB) apps can (and really should) be produced that way.

    However, this approach usually doesn’t work for more “system” level products.

    Check out Model-Driven Architecture [1]. Most likely you’ll be able to configure an MDA toolchain to generate the code you want

    [1] MDA https://en.wikipedia.org/wiki/Model-driven_architecture