What is RESTful, talk about RESTful I understand.

First, what is RESTful resource-oriented
Simply put: RESTful is an architecture of norms and constraints, in principle, in line with the architecture of this specification is a RESTful architecture.

What does it mean to look at REST, English Representational state transfer representational state transfer of resources is actually a representational state transfer.
(What is a statement of: refers to the client requests a resource, the server to get the resources, that is, representation)
address resources in the web is the URL (Uniform Resource Identifier)
resources is the core concept of REST system. All designs are based resource center

How to combine resources to identify projects
1. goods into the shopping cart Shopping cart
2. Submit Order Order
3. Create a User

Add, retrieve, modify, delete, and resources that meet specific criteria for a list of resources about the operation. Resources for the design of the interface

Second, on the norms and constraints What?
Core Specification and restraint RESTful architecture: a unified interface
is divided into four sub-constraints:
1. Each resource has a resource identifier, resource identifier of each resource can be used to uniquely indicate the resource
2. The message is self-describing
3. self-descriptive resources.
4.HATEOAS Hypermedia As The Engine Of Application State ( hypermedia application state as an engine)
i.e., only the information of each customer contained in the results can be returned by the server to obtain the information required for the next operation, such as in the end to which URL is transmission request and the like. In other words, a typical REST service does not require additional documentation which indicated URL to access specific types of resources, but in the end to indicate what kind of operations can be performed on the resource response returned from the server

Objective: To achieve the client does not need all of that is able to invoke the aid of any document server resources

 

Three, URL resource design
1, to identify resources by URL

Resource resource sub-divided into a main resource
as a primary resource class independent resource is therefore the main resource should be placed directly under the relative path: for example,
to represent the primary resource instance: if the instance of ID = 1, then this represents: / goods / 1
sub-resource:
subresource one example might be a collection may also be a single child resource
sub-resources for the picture set: / goods / 1 / pictures
sub resource list of sub-resource commodity discount: / goods / 1 / discount

2, plural vs. singular

1 user access to information, which way is more in line with RESTful?
/ API / the Users / 1
/ API / the User / 1

3, the relative path request parameter vs

Aurora RESTful API:
acquiring user information GET / v1 / users / {username } parameter in the path
VS
? Xxxxx splicing acquired user information GET / v1 / users username = manner

Application administrators get a list of GET / v1 / admins? Start = {start} & count = {count}? Manner after splicing parameters: filtering resources in this manner generally as

4, using the appropriate verb get delete put post

Select the request interface way: the Delete GET
PUT update the resource (after the complete resources provided by the client to change) in the server.
POST Create a resource server

5, using the standard status code

GET
safe and idempotent
acquisition represents
Gets the time change (cache)
200 (the OK) - represents the response has been issued in
204 (no content) - available resource represents
301 (Moved Permanently) - URI of the resource has been updated
303 (See other) - other (e.g., load balancing)
304 (not Modified) - resources are not changed (cache)
400 (bad request) - refers bad request (e.g., parameter error)
404 (not found) - resource does not exist
406 (not acceptable) - the server did not support the required
common error response - 500 (internal server error)
the server can not process the current request - 503 (-service Unavailable Papers with)
the POST
unsafe not idempotent
instance management server (automatically generated) of No. create a resource
to create a child resource
section to update the resource
if it is not modified, but the updated resource (optimistic locking)
200 (the OK) - If the existing resource has been changed
201 (created) - If a new resource is created
202 (accepted) - has accepted but not completed processing the request (asynchronous processing)
301 (Moved Permanently) - URI of the resource is updated
303 (See other) - other (eg, Load balancing)
400 (bad request) - refers Bad Request
404 (not found) - resource does not exist
406 (not acceptable) - the server does not support the required representation
409 (conflict) - Universal Conflict
412 (Precondition Failed) - Precondition Failed ( as conflicts when execution condition update)
415 (unsupported Media of the type) - received representation is not supported
500 (internal server error) - generic error response
503 (service Unavailable) - service is currently unable to handle the request
PUT
unsafe but idempotent
with examples of client management to create a number of resource
-renewable resources through alternative ways
, if not modified, the update resource (optimistic locking)
200 (the OK) - If there is a resource already been changed
201 (created) - If a new resource is created
301 ( Moved Permanently) - URI resource has changed
303 (See other) - other (eg, load balancing)
400 (bad request) - refer bad request
404 (not found) - the resource does not exist
406 (not acceptable) - the server does not supports the required representation
409 (conflict) - universal conflict
412 (precondition failed) - precondition failed (e.g. more execution condition When the new conflict)
415 (unsupported media type) - received representation is not supported
500 (internal server error) - generic error response
503 (Service Unavailable) - service is currently unable to handle the request
DELETE
unsafe but idempotent
delete the resource
200 (OK) - resources have been is deleted
301 (Moved Permanently) - URI resource has changed
303 (See other) - other, such as load balancing
400 (bad request) - refer to bad request
resource does not exist - 404 (not found)
409 (conflict) - universal conflict
500 (internal server error) - generic error response
503 (service Unavailable) - the server can not process the current request
6, select the appropriate representation structure

json xml

text link: https: //blog.csdn.net/riemann_/article/details/88212080

Guess you like

Origin www.cnblogs.com/ldddd/p/11422157.html