About REST

REST: Use the HTTP protocol according to HTTP semantics

1. URL is used to locate resources: /user/888, /user/888/orders

2. HTTP predicates: GET, POST (new), PUT (overall update), DELETE, PATCH (partial update), etc.

3. What is "idempotence"? What are some examples? DELETE, PUT, and GET are idempotent, but POST is not idempotent (idempotent: if it occurs once or multiple times, the result is the same)

4. GET responses can be cached

5. The server side must use status codes to reflect the results of resource acquisition: 404, 403 (no permission), 201 (newly added successfully)

Advantages and Disadvantages of REST

advantage

1. Locate resources through URL, making the semantics clearer

2. Represent different operations through HTTP predicates, and the interface is self-describing

3. You can retry GET, PUT, and DELETE requests.

4. You can use GET requests for caching

5. Reflect the server-side processing results through HTTP status codes and unify the error handling mechanism

6. Gateways, etc. can analyze the request processing results

shortcoming

1. The resources in the real system are very complex, and it is difficult to clearly divide the resources, which requires high business and technical levels of technical personnel.

2. Not all operations can be simply mapped to certain HTTP verbs.

3. System evolution may change idempotence

4. Resource locating through URL is not in line with the habits of Chinese users.

5. The number of HTTP status codes is limited

6. Some links will tamper with response messages with non-200 response codes.

7. Some clients do not support PUT and DELETE requests.

Guess you like

Origin blog.csdn.net/2201_75837601/article/details/128730668