Today, you will learn the concept of Richardson’s Maturity Model(RMM)
How do you measure if a web service is REST web service or not?
|Richardson’s Maturity Model for RESTful APIs|
This can be done using a model developed by a Computer Scientist called Roy Fielding. This model is called Richardson’s Maturity Model and is use to determine how much the API conforms the certain architectural styles.
It is used to answer the question: How RESTful is the API? Based on certain criteria, a REST API can can score from 0 – 3 ranging from Not-RESTful (level 0) to Fully-RESTful(level 3)
Level 0: Not RESTful
At level 0 a REST API is described as not RESTful. This means that the API is made up just XML and therefore known as ‘Swamp of POX’, plain old xml. At level 0, the request and response uses just on entry point URI and just one method HTTP POST method. Level 0 is equivalent to SOAP(Simple Object Access Protocol) web service
Level 1: Resource-based URIs
Level 1 has to do with Resource and Resource-based URIs. This means that there are different URIs for different resources in the API. URI stands for Universal Resource Identifier. It is similar to a URL. The difference is that a URI is a URL that maps to a particular resource.
Resources are endpoints in the API which could represent an object, collections of objects, operations on objects etc.
Take example of URL from a messaging application:
- The first line is a URI that maps to a collection of messages and a returns a list of messages to the client.
- The second line maps to a single message with ID of 1 and sends back the message with the id of 1 to the client.
- The third URI maps to the delete operation for message with ID of 2 and allows the user to delete the message
So if your REST API has the URIs designed this way, then that API have attained to REST level 1.
Level 2: HTTP Methods (or Verbs)
If a REST API implements resource-based URIs and also uses the appropriate HTTP verb to perform operations, then the API have attained REST level 2.
The HTTP verbs corresponds to the four CRUD operations that can be performed on a resource. The verbs are:
- GET: used to retrieve resource(s) from the server
- POST: used to create new resource
- PUT: used to modify existing resource
- DELETE: used to delete a resource from the server
So if a client makes a request to retrieve a resource from the server, the it should use the REST the GET method.
The fact is that without the use of HTTP verbs, the API would still work but would not be fully RESTful.
Level 3: HATEOAS Compliant
To attain level 3 after attaining level 2, then the API must be HATEOAS compliant. HATEOAS stands for Hypermedia as the Engine Of Application State. Of course you know what Hypermedia is. Typical example is hyperlinks. So this level requires that the API must provide in addition to the response, links to other resources or operations that the client may need.
So if a client request for a resource, say a user profile, then the API should provide the user with links to Edit, Delete and Save as well as link to get list of users.
This level is what makes is possible to browse a website without much help because the hyperlinks and images provide the user with hints on how to move to a different part of the application(changing the application state)
So a REST API at level 3 is described as fully RESTful. I hope this explanation is clear. Please leave a comment if you would like to.