First of all, what is rest?
Rest is literally called the representational state Transfer, translated into a presentation layer status transfer, but generally in translation, a resource is preceded by the resource representational state Transfer, that is, the resource performance layer state transfer. Employing words is: The client through the HTTP request, the server-side resources to operate, implementation of the "performance layer (using HTTP verbs to promote server-side resources) state changes." Two. What is restful?
RESTful is meant to be restful, or designed to conform to the rest architecture, so to understand restful you need to know rest.
Three. Why do we use the restful style to develop interfaces?
Look at the traditional way of designing interfaces:
Add an employee: HTTP://WWW.DEMO.CN/FINANCE/EMPLOYEE/CREATEEMP
Delete an employee: HTTP://WWW.DEMO.CN/FINANCE/EMPLOYEE/DELETEEMP
Modify an employee: HTTP://WWW.DEMO.CN/FINANCE/EMPLOYEE/UPDATEEMP
Get Employee List: HTTP://WWW.DEMO.CN/FINANCE/EMPLOYEE/LISTEMP
Now we find out: a very simple demand-generating problem:
1. Each operation requires a separate URL to operate, because we need to reflect the action of the employees in the URL.
2. Will produce a large number of URLs, very inconvenient interface maintenance and document maintenance
3. If there are different ways of responding, we may need additional parameters, or even different URLs to describe
4. The request parameter is included in the request address and cannot be targeted for caching
If we use the RESTful style interface, then we can do the following:
Add one employee: POST Http://www.demo.cn/finance/employee
Delete an employee: delete Http://www.demo.cn/finance/employee
Modify an employee: PATCH Http://www.demo.cn/finance/employee
Get list of employees: getting Http://www.demo.cn/finance/employee
It can be found that we give the different meanings of these requests through HTTP requests, and the action design and examples are as follows:
Here's a simple practice where we can use the open source Yapi to help us manage interfaces and test: