Today Solomon_ Xiao ge play architecture to share with you the role of Rest Ful and use value in the project, welcome to visit 🔥Serverless micro services elegant shutdown practices, like, like, like. Follow my public account Solomon for more surprises
Introduce a RestFul
REpresentational State Transfer (RestFul) Style Objective: Specifies resource interpretation methods and operation rules.
Disadvantages of traditional URL resource definition
- There is no unified specification of the URL, combining verbs and names, and it is difficult to understand the specific business meaning through the URL resource directional marking
- The problem with non-standard urls in large projects is that they are difficult to manage and maintain
- Everyone has a unique understanding of the resource rules, so what is the real standard, a lot of specifications, identification, and ultimately just arbitrary, and then the resource tag corrupts
RestFul role
- Each URI represents a resource
- Through the unified standard style specification to constrain the expression of resources, its structure is clear, conform to the standard, easy to understand, easy to expand, so is getting more and more sites to adopt
- Use four HTTP verbs to perform operations on server-side resources to achieve “presentation layer state transformation”
RestFul case
The way in which project members are operated
RestFul path Rules
Resource path rules clearly indicate the hierarchical relationship between resources, as follows:
/order/{orderID} : Specifies the order details
/order/{orderID}/products: specifies the products associated with the order
/order/{orderID}/products/{id} : the specified goods under the specified order
Note: Use nouns when locating resources, as actions are described in Method.
RestFul protocol format
Protocol format: Method + space +URL (Resource Direction) [? Filtering criteria]+ protocol version + operator
Resource action
Method (Resource manipulation behavior, changing the state of the resource)
GET: Requests a server specific resource.
POST: The server creates a new resource.
PUT: Updates the server resource (the entire resource).
DELETE: the server deletes a specific resource.
PATCH: Updates the resource (part of the resource) on the server.
Examples of action and resource coordination
GET /order/{orderID} : Gets the details of the specified order
Resource Representational State Transfe Description
-
Resource:
- Service-side specific resources, and each specific resource has its own URI.
-
Representational:
- “Resources” in various forms. Such as json, XML, image, TXT.
-
State Transfer:
- Use Method to change the state of a server – side resource.
Your likes and attention are the continuing power of the Solomon_Chaug framework.