Richardson Maturity Model
Richardson Maturity Model grades API by their RESTful maturity. It is proposed by Leonard Richardson. The Richardson maturity model is a way to grade your API according to the constraints of REST. It breaks down the principal element of the REST approach into four levels (0 to 3).
There are four levels:
For example, a level higher is more RESTful compared to one that is at a lower level. Only when an API reaches level 4, we consider it as a RESTful API.
Level 0: The Swamp of POX
Level 0 is also known as POX (Plain Old XML). At level 0, HTTP is used only as a transport protocol that is used as a remote interaction. It does not take the advantages of HTTP like different HTTP methods, and HTTP cache. To get and post the data, we send a request to the same URI, and only the POST method may be used. These APIs use only one URI and one HTTP method called POST. In short, it exposes SOAP web services in the REST style.
For example, there can be many customers for a particular company. For all the different customers, we have only one endpoint. To do any of the operations like get, delete, update, we use the same POST method.
To get the data: http://localhost:8080/customer
To post the data: http://localhost:8080/customer
In the above two URIs, we have used the same URI and method to get and post the customers.
Level 1: Resources
When an API can distinguish between different resources, it might be at level 1. It uses multiple URIs. Where every URI is the entry point to a specific resource. It exposes resources with proper URI. Level 1 tackles complexity by breaking down huge service endpoints into multiple different endpoints. It also uses only one HTTP method POST for retrieving and creating data.
For example, if we want a list of specific products, we go through the URI http://localhost:8080/products. If we want a specific product, we go through the URI http://localhost:8080/products/mobile.
Remember the following points while building a URI:
Level 2: HTTP Verbs
Level 2 indicates that an API must use the protocol properties to deal with scalability and failures. At level 2, correct HTTP verbs are used with each request. It suggests that in order to be truly RESTful, HTTP verbs must be used in API. For each of those requests, the correct HTTP response code is provided.
We don't use a single POST method for all requests. We use the GET method when we request a resource, and use the DELETE method when we want to delete a resource. Also, use the response codes of the application protocol.
For example, to get the customers, we send a request with the URI http://localhost:8080/customers, and the server sends proper response 200 OK.
The following table shows the HTTP verbs and their usage:
Level 3: Hypermedia Controls
Level 3 is the highest level. It is the combination of level 2 and HATEOAS. It also provides support for HATEOAS. It is helpful in self-documentation.
For example, if we send a GET request for customers, we will get a response for customers in JSON format with self-documenting Hypermedia.
The following figure shows the overview of the model: