-1

I've been developing several front-end web-applications recently that bind against a database using a RESTful CRUD api.

I've noticed a massive amount of boilerplate code going into defining the API. For example, on the back-end I define a db-schema, controller, api endpoint, and view-model. On the front-end, I expose events, consume the view-model, bind my data, and hook up my UI.

Instead of re-implementing a set of CRUD API actions each time I add to my db-schema, it seems it would be easier to create a management system that would automatically create API actions based on db schema. Then implement a similar generic binding on my front end.

Is there a design pattern, development process, developing methodology, etc. for this?

1 Answers1

0

You basically have three options

  1. Hand code the boiler plate
  2. Generate the code with templates
  3. Implement a generic query interface

The problem with 2 is that generally you do have some specific methods that you want to use in addition to the standard CRUD ones. GetCustomerByPostCode or GetRecentlyLookedAtItems etc. You end up tweaking the generated code to your needs.

The problem with 3 is that A the queries aren't limited to the ones you predefine, and B sometimes the SQL query your query language creates is less performant than one you could write yourself.

In my experience 1 isn't a bad solution.

Ewan
  • 83,178