Recently I am involved in building a Campaign Management System based on Richardson's Level 3 service definition. It's a new thing for my team and we are enjoying it. Leonard Richardson proposed a classification of RESTful web services in his talk. He mentioned four levels in his classification. Richardson evaluated service maturity based on three core technologies: URI, HTTP and Hypermedia. Each layer builds on the concepts and technologies of layers below.
So what are characteristics of these levels?
Level 0 Services
- HTTP is used as a transport system to tunnel requests and responses.
- A single URI.
- Use a single HTTP method (typically POST), ignore the rest of the HTTP verbs.
- Examples: SOAP, XML-RPC and POX (Plain Old XML).
Level 1 Services
- Introduce Resource concept.
- Employ many URIs and each URI acts as an entry point to a specific resource.
- Still a single HTTP verb is used.
Level 2 Services
- At this level services host many URI-addressable resources and also support several of the HTTP verbs on each exposed resources.
- The use of GET for requesting resource is important. HTTP defines GET as safe and idempotent operation. This property of GET help us to optimize the services. When a consumer of a resource uses GET, we know he does not want to modify it. We can use caching to store responses closer to our consumer. Subsequent requests will be served from the caches and that helps in improving the overall quality of the service.
- Another important characteristic is the use of status codes. Services use different status codes to respond. When a resource is created, services respond with a 201 Created whereas 409 Conflict is used to tell that something has gone wrong.
Level 3 Services
- Support HATEOAS (Hypermedia As The Engine Of Application State)
- Now the representations contain URI links. These links may point to other resources (may be interesting to the consumers) or they may represent a transition to a possible future state of the current resource. One important thing to notice here - service tells the consumer what to do next through these links.
- Here the consumer submits an initial request to the entry point of the service. The service handles the request and responds with a resource representation populated with links. The consumer chooses one of these links to transition to the next step in the interaction. Over the course of several such interactions, the consumer progresses toward its goal. In this way the distributed application's state gets changed.
- Consumers in a hypermedia system cause state transitions by visiting and manipulating resource state.
- REST in Practice - Jim Webber, Savas Parastatidis, Ian Robinson
- Martin Fowler's article on Richardson Maturity Model