banner api

What is Richardson Maturity Model?

It is a model (developed by Leonard Richardson) to improve API maturity.

To achieve the glory of REST, the API must have maturity levels. There are 4 levels, and next we will see how each of them works.

Level 0: The Swamp of POX

This level defines that the use of the HTTP protocol is necessary to transport the information.

We have a single endpoint for all requests, using only one HTTP VERB, which in this case is POST.

Examples:

  • https:myapi/v1/states?action=list
  • https:myapi/v1/states?action=add

Level 1: Resources

Now we no longer have a single endpoint, but we are still using the POST verb for all endpoints. We use resources as in the examples:

  • https:myapi/v1/states/getAllStates
  • https:myapi/v1/states/getStateById

Level 2: HTTP Verbs

We make proper use of HTTP verbs to indicate each action.

Among the most commonly used are:

  • GET: responsible for retrieving one or more resources;
  • POST: responsible for creating a new resource;
  • PUT: responsible for updating a resource;
  • DELETE: responsible for removing a resource;
  • PATCH: responsible for partially updating a resource.

Examples:

Level 3: Hypermedia Controls

In this final level of maturity, we apply HATEOAS (Hypermedia as the Engine of Application State). It is responsible for showing the URI of the resource itself and other resources related to it. It’s like website navigation.

Example:

{
  "states": [
    {
      "id": 1,
      "name": "São Paulo",
      "links": [
        {
          "rel": "self",
          "href": "http://api.example.com/v1/states/1"
        }
      ]
    },
    {
      "id": 2,
      "name": "Rio de Janeiro",
      "links": [
        {
          "rel": "self",
          "href": "http://api.example.com/v1/states/2"
        }
      ]
    }
  ],
  "links": [
    {
      "rel": "first",
      "href": "http://api.example.com/v1/states?page=1"
    },
    {
      "rel": "next",
      "href": "http://api.example.com/v1/states?page=3"
    },
    {
      "rel": "prev",
      "href": "http://api.example.com/v1/states?page=1"
    },
    {
      "rel": "last",
      "href": "http://api.example.com/v1/states?page=10"
    }
  ]
}

Pagination is a good example of its use, but it’s not limited to that, as it returns the possible actions related to the returned resource.

This is how we can achieve the glory of Rest.

References

https://martinfowler.com/articles/richardsonMaturityModel.html: What is Richardson Maturity Model?

Author

  • Natan Ferreira

    Hello there, I’m Natan Lara Ferreira, Full Stack Developer Java and Angular since 2016. I’m in Open Finance Brazil project using framework Quarkus and Angular since the beginning 2021. I'm a problem solver, critical thinker and team player.