Search code examples
architectureclean-architecture

How can I create a RESTAPI without a provided database?


I'm currently facing a challenge in developing a RESTful API using either Express.js or Hapi.js. The main issue I'm encountering is the unavailability of a suitable database for my project. However, I do have some information about the tables present in the database, without any clear explanation of their relationships or detailed business logic.

I'm seeking advice and solutions from experienced developers who might have encountered a similar situation or have knowledge of tools that can help me overcome this problem. Is there a way to start building the API without having to wait for the actual database to be available, while still ensuring it can be seamlessly integrated once the database is ready?


Solution

  • If I understand your question correctly, you're asking about how to start writing business logic before the database layer is finalized.

    This is addressed in Robert C Martin's book "Clean Architecture".

    The gist of it is: You can decouple most of your application from the database, by accessing the database through a layer of objects called "Entity gateway"s, which are responsible only for transforming the db structure to business objects (for reading) or the business objects to db structure (for writing).

    That way when the database is finalized, all you need to do is implement or change the implementation of those entity gateways, and the rest of the system doesn't need to change.

    This also makes it easier to make changes in the database in the future, because again the only things that will need to change are the entity gateways.

    More info: https://youtu.be/Nsjsiz2A9mg?t=2979