RESTful Web Service
REST architecture provides a set of constraints, when applied as a whole, it emphasizes the interaction component scalability, independent deployment versatility, the interface components, and to reduce interaction latency, enhanced security, leaving encapsulate legacy system intermediate components.
Richardson Maturity Model
Level 0: not use substantially entirely on the REST it using a URI http a method to process all requests is very confusing
Level 1: resource request to distinguish, however, or the use of a URI http operation i.e. a processing request
Level 2: to distinguish between different httpmethod say what a url when dealing with post processing and so get
Level 3: use a hypermedia hypermedia drive
How to achieve Restful Web Service
Divided into the following categories:
- Identify resources
- Select the appropriate resource granularity
- Design URI
- Select the appropriate method and HTTP return code
- Design Resources representation
Identify resources
- Find areas of nouns
• use nouns CRUD operations
such as used coffee before and coffeeorder operation carried out http - The organization is a collection of resources (ie, a collection of resources)
together such as all coffee is coffee put together a collection of all coffeeorder placed is a collection of coffeeorder - Resources combined into a composite resource
that is set and the coffee to form a composite set of resources coffeeorder - Computing or processing management functions
such as calculated from Shanghai to Beijing
Select the appropriate resource granularity
Standing server point of view, to consider
- Network efficiency
in a network interaction process as many things - How many expressed
expressed how much design - Ease of use the client
how to use the client is convenient
Standing on the client's point of view, to consider
- Cacheability
whether to allow the cache if allowed How often updated cache, etc. - Modify the frequency
- Variability
information is variable
Building a better URI
- Use the domain and sub-domains of resources into logical groupings or division
- Delimiters slash part of the URI path (/) to represent hierarchical relationships between resources
- In the part of the URI path with a comma (,) and the semicolon (;) to represent the non-hierarchical element
- Use a hyphen (-) and underscores (_) to improve the readability of the name of a long path (embody hump rules)
- In use the URI query part "and" symbol (&) to separate the parameters
- Avoid file extension appear in the URI (eg .php, .aspx and .jsp)
Understanding of HTTP methods
Idempotent: No matter how many times I requested resource request is the same
safety: I would not change a variety of content resources
The method of HTTP URI in combination with
Understanding of HTTP status codes
2 at the beginning of the status of all status codes are successful code
all three status code beginning with a jump all the relevant cache redirection status code
all 4 status codes are beginning Client Error status code
all five status code beginning all server error status code
Select the appropriate representation
Divided into the following categories:
JSON (Main)
- MappingJackson2HttpMessageConverter
- GsonHttpMessageConverter
- JsonbHttpMessageConverter
XML (giving reading)
- MappingJackson2XmlHttpMessageConverter
- Jaxb2RootElementHttpMessageConverter
HTML
protobuf
- ProtobufHttpMessageConverter