如何创建一个没有提供数据库的REST API?

huangapple go评论55阅读模式
英文:

How can I create a RESTAPI without a provided database?

问题

我目前在使用Express.js或Hapi.js开发RESTful API时面临一个挑战。我遇到的主要问题是找不到适合我的项目的数据库。但是,我确实了解到数据库中存在的一些表格的信息,但没有清晰的关系或详细的业务逻辑解释。

我正在寻求有经验的开发者的建议和解决方案,他们可能遇到过类似的情况或了解可以帮助我解决这个问题的工具。是否有一种方法可以开始构建API,而无需等待实际数据库可用,同时仍然确保在数据库准备好后可以无缝集成?

英文:

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?

答案1

得分: 0

以下是翻译好的内容:

如果我正确理解你的问题,你正在询问在数据库层最终确定之前如何开始编写业务逻辑。

这在罗伯特·C·马丁的书《Clean Architecture》中有详细介绍。

其要点是:你可以通过访问数据库的对象层次结构,称为“实体网关”,将应用程序的大部分与数据库解耦,这些实体网关仅负责将数据库结构转换为业务对象(用于读取)或将业务对象转换为数据库结构(用于写入)。

这样,当数据库最终确定时,你只需要实现或更改这些实体网关的实现,而系统的其余部分不需要改变。

这还使得在将来更改数据库变得更容易,因为需要更改的只是实体网关。

更多信息:https://youtu.be/Nsjsiz2A9mg?t=2979

英文:

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

huangapple
  • 本文由 发表于 2023年5月25日 16:53:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76330471.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定