单个 API 与不同 API 中的 CRUD 操作

Crud operations in single API vs different API'S

在构建 API 时,我们使用不同的方法进行 CRUD 操作。有时我们构建单个 API 来一起处理插入、更新和删除。有时我们构建不同的 API'S 来分别处理每个操作,例如插入单独 API、更新单独 API 和删除单独 API。我想知道哪种是最好的方法。如果是这样,为什么。任何证明相同的文件。

推荐的方法,至少根据 here 是有多个 API 端点(我假设这就是你说 不同 [=36] 的意思=]'s) 并使用可用的各种 HTTP 方法区分它们。

例如:

  • [HTTP GET] /product: 读取数据库中的所有可用产品
  • [HTTP GET] /product/123: 获取产品 123 的具体信息。
  • [HTTP POST] /product: 通过API创建新产品。
  • [HTTP PUT] /product/123:通过 API.
  • 更新现有产品
  • [HTTP DELETE] /product/123: 通过API删除产品123。

尽管所有路由看起来都很相似,但它们会依次映射到控制器中的各种方法 class,这些方法会相应地执行必要的任务。

网站 Link - Click here to visit and more details

文章作者 - Mahipal Nehra His LinkedIn

Types of APIs

The classification of APIs can be done on three parameters which are listed as follows:

Ownership types of Web APIs

On Ownership level there are four main types of APIs:

Open APIs: These APIs are publicly available to use like Oauth APIs from Google and there is no restriction to use them. Hence, they are also known as Public APIs.

Partner APIs: Specific rights or licenses in order to access this type of API because they are not available to the public. Usually, these kinds of APIs are associated with paid services

Internal APIs: The APIs that are developed by companies to use into their internal systems so that they can enhance the productivity of development teams where one team can use services from another project of the company is called Internal APIs. These APIs are also known as Private APIs.

Composite APIs: Both processes and composite APIS are a sequence of tasks but composite APIs combines different data and service APIs. It is a sequence of tasks that run synchronously as a result of the execution where the result of triggering of a Composite API is the result of the execution and not the request that will contain the result of the execution at the request of a task. Its main usage is to speed up the process of execution and improve the performance of the listeners in the web interfaces.

Communication level of APIs

High-Level APIs

High-level APIs are those that we use generally in REST form where programmers have a high level of abstraction and they are only concerned about performing a limited functionality.

Low-Level APIs Low-level APIs have a lower level of abstraction hence they are most detailed, which allows the programmer to manipulate functions within an application module or within hardware at a granular level. Usually, Low-level APIs are used in sending the real-time video or media feed in response to a trigger like Vulkan APIs.

Web service APIs In web service APIs the classification is done on the type of communication and behavioural approach used in building APIs:

*SOAP

*XML-RPC

*JSON-RPC

*REST

Web service APIs are small applications that use URLs or web addresses on the internet to provide their services to desktop, mobile, web applications and others.