restful-api_您的API有多RESTful-理查森成熟度模型

restful-api

Since REST is just a specification or we can say a way of implementing web services, with no hard coded documentation. So how we know the API which we have developed is fully RESTful. For this, there is Richardson Maturity Model, which is usually referred to analyse how RESTful the API is.

由于REST只是一个规范,或者我们可以说是一种实现Web服务的方法,而没有硬编码的文档。 因此,我们如何知道已开发的API是完全RESTful的。 为此,存在理查森成熟度模型 ,通常将其用于分析API的RESTful程度。

The Richardson Model is a way to grade your API according to the constraints of the REST. The more the API follows these constraints the more RESTful the API is.

理查森模型(Richardson Model)是一种根据REST约束对API分级的方法。 API遵循这些约束越多,RESTful API就越多。

The Richardson Maturity Model has 4 levels numbered from 0 to 3. Level 0 is not RESTful while Level 4 means your API is fully RESTful.

理查森成熟度模型有4个级别,从0到3。 级别0不是RESTful,而级别4表示您的API是完全RESTful。

0级 (Level 0)

This will use only one URI to expose the whole API and generally uses only one HTTP method. If we take example of our registration API we see that that every resource has its own URI. The student resource has a different URI, the course resource has a different URI and the registration resource has a different URI.

这将仅使用一个URI公开整个API,并且通常仅使用一种HTTP方法。 如果我们以注册API为例,则会看到每个资源都有其自己的URI。 学生资源具有不同的URI,课程资源具有不同的URI,注册资源具有不同的URI。

SOAP based web services are the example of this level. This level of API doesn't leverage the full concepts of the HTTP specification. For example: Every request will be POST request, so if someone wants to delete a student record they will have send the action also in the request.

基于SOAP的Web服务就是该级别的示例。 此级别的API并未利用HTTP规范的完整概念。 例如:每个请求都是POST请求,因此,如果有人要删除学生记录,他们也将在请求中发送操作。

1级 (Level 1)

In this level every resource has its own URI. This level uses multiple URI where every URI is an entry point to a specific resource. Still this level uses only POST method for operation.

在此级别,每个资源都有其自己的URI。 此级别使用多个URI,其中每个URI都是特定资源的入口点。 此级别仍仅使用POST方法进行操作。

2级 (Level 2)

This level says that your API should use protocol properties as much as possible. You must not use single POST method for all the operations, but make use of GET when you are requesting a resource, use a DELETE method when you want to delete a resource.

此级别表示您的API应该尽可能使用协议属性。 您不得对所有操作使用单个POST方法,而在请求资源时使用GET ,在要删除资源时使用DELETE方法。

The use of proper response codes is also essential. Use 201 Created response code when a post request comes and resource is created. Use 200 Ok response for the get request and so on.

使用正确的响应代码也是必不可少的。 发布请求到来并创建资源时,使用201 Created响应代码。 对get请求使用200 Ok响应,依此类推。

3级 (Level 3)

This level suggests to use the concept of HATEOAS. The response should contain the logical links of all the resources which the current resource is related to.

此级别建议使用HATEOAS的概念。 响应应包含当前资源所关联的所有资源的逻辑链接。

For Example: In case of when the client request for the student information with the roll number 1, then in the response along with the response of the student, a link of all the URI of all the courses which that student has registered should also be sent.

例如:如果客户要求卷号为1的学生信息,则在响应以及学生的响应中,该学生已注册的所有课程的所有URI的链接也应为已发送。

If an API is at the level 3 this will be known as fully RESTful. This Richardson Model should be used while designing the REST API to make sure the web services are fully RESTful.

如果API处于3级,则称为完全RESTful 。 在设计REST API时应使用此Richardson模型 ,以确保Web服务完全是RESTful。

翻译自: https://www.studytonight.com/rest-web-service/richardson-maturity-model

restful-api

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值