What is RESTful

REST translates as “Representational State Transfer.” It was proposed by Roy Thomas Fielding in his doctoral dissertation in 2000. Roy explained the best architectural style in web applications, REST, from the perspective of architectural style.

If an architecture conforms to REST principles, it is a RESTful architecture. HTTP is a good example of RESTful architecture. REST, in contrast to RPC, can be understood as resource-oriented. The client does not need to know the specific methods of the server, but instead represents the resource through a URI. REST emphasizes communicating as much information as possible within the semantics of the HTTP protocol itself, so it focuses more on interface specifications.

RESTful hierarchy

Use the Richardson Maturity Model to describe the Maturity level of RESTful apis.

1. Level 0: POX swamp

This level of API is not a REST API, but a WEB service based on SOAP or RPC. HTTP is only a transport layer protocol, with parameters in the body, posted to a public service endpoint on a URI, and content can be passed as XML (POX), JSON, YAML, key-value pairs, or any custom format.

2. Level 1: resource-based URI

The starting level of REST APIS is also the first step towards REST. Instead of sending all requests to a single exposed service endpoint, abstract the service into a resource. Put the requested resource in the URI, rather than as a parameter in the header. Compared with the Level 0, don’t need to know the specific services, as long as know the service address, according to the path of the resource can access services, such as http://127.0.0.1:3000/books/1.

3. Level 2: HTTP predicate

RESTful applications at this level can make full use of THE capabilities of HTTP for application-layer protocols and are the most widely used layer at present. Both Level 0 and Level 1 use the POST method to interact. Level 2 defines HTTP add, delete, modify, and query methods.

  • GET – Obtains server resources. A relatively safe operation that can be called multiple times in any order
  • POST – Creates a new resource on the server
  • PUT – Changes server resources
  • DELETE – Deletes server resources

The COMBINATION of HTTP predicates and resources can accurately represent “do XX (action) to XX (resource).” The server tells the client the result of the request execution through HTTP status codes, reducing the coupling between the server and the client.

4. Level 3: Hypermedia control

The highest level of the RNN model leverages HATEOAS (Hypertext application state Engine).

With HATEOAS, the server provides hypermedia dynamic information, that is, returns self-descriptive data structures. The client can know the details of the next available resource and what can be done with it, so that the resource can be loaded “on demand” without the need for API documentation.

For example, if a client requests information about a user of Sina Weibo, the REST service can return user details, get links to the people he follows, get links to his most recent tweets, get links to his most recent comments on tweets, and so on.

Another benefit of this is that the server can add new links in the response to add new functionality, or modify the URI scheme without affecting the client.

Third, summary

The RNN model is not defined at the REST level itself, but rather provides a step by step approach to understanding RESTful architecture and helps us better design apis for business scenarios.

Reference:

Know how RESTful your API is: An Overview of the Richardson Maturity Model

Richardson Maturity Model- Towards the Apex of REST

Restful Levels hierarchy and the HATEOAS principle