VOOZH about

URL: https://www.geeksforgeeks.org/node-js/richardson-maturity-model-restful-api/

⇱ Richardson Maturity Model - RESTful API - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Richardson Maturity Model - RESTful API

Last Updated : 23 Jul, 2025

The Richardson Maturity Model (RMM), proposed by Leonard Richardson, is a model used to assess the maturity of a RESTful API based on its implementation levels. It consists of four levels, each representing a stage of maturity in the design and implementation of RESTful principles. Let's delve into each level to understand how APIs progress through the model. In determining the maturity of a service, Richardson emphasized three main factors. They include:

  • URI
  • HTTP Methods
  • HATEOAS (Hypermedia)

URI

A Uniform Resource Identifier (URI) is a unique sequence of characters used by web technologies to identify resources on the web.

HTTP Methods

Hypertext Transfer Protocol (HTTP) is a protocol used to transfer hypermedia documents. HTTP requests are sent to servers by HTTP clients in the form of request messages. HTTP defines a set of request methods to specify the action to be taken on a given resource.

  • GET: The GET method retrieves a representation of the specified resource.
  • POST: A POST request transmits data to the server.
  • PUT: The PUT method replaces all existing representations of the resource.
  • PATCH: A PATCH request makes partial changes to a resource.
  • DELETE: The DELETE method removes the specified resource.

HATEOAS

HATEOAS (Hypermedia as the Engine of Application State ) refers to discoverability. The client can interact with a REST API solely through the server’s responses. It is a self-documentary Hypermedia. Clients need not refer to any documentation to interact with a new API.

REST services are divided into maturity levels according to the Richardson Maturity Model.

Level 0: The Swamp of POX (Plain Old XML)

Characteristics:

  • Uses HTTP as a transport protocol but doesn't leverage its features.
  • Often relies on a single endpoint (e.g., POST /api) for all operations.
  • Treats HTTP as a tunnel for remote procedure calls (RPC).
  • Doesn't follow resource-oriented architecture.

Key Issues:

  • Lack of resource-based URLs.
  • No use of HTTP methods like GET, POST, PUT, DELETE.
  • Absence of hypermedia controls.

Level 1: Resources

Characteristics:

  • Introduces the concept of resources as the key abstraction.
  • Resources are exposed as individual URLs (e.g., /users, /products).
  • Utilizes HTTP methods (GET, POST, PUT, DELETE) to perform operations on resources.
  • Uses different URLs for different operations (e.g., POST /users to create, GET /users/:id to read).

Key Issues:

  • May not use HTTP methods correctly (e.g., using only POST for all operations).
  • Does not leverage hypermedia controls.

Level 2: HTTP Verbs

Characteristics:

  • Adheres to proper usage of HTTP methods (GET, POST, PUT, DELETE).
  • Uses HTTP headers (e.g., Content-Type, Accept) for negotiation and metadata.
  • Each HTTP method has a specific role in manipulating resources (e.g., GET for retrieval, PUT for update).
  • Leverages status codes (e.g., 200 OK, 404 Not Found) to convey operation results.

Key Advancements:

  • Enhances API consistency and predictability.
  • Facilitates better understanding and debugging of API interactions.
  • Enables caching and optimization based on HTTP features.

Level 3: Hypermedia Controls (HATEOAS)

Characteristics:

  • Represents the highest level of RESTful maturity.
  • Integrates hypermedia controls within API responses (e.g., links, actions).
  • Allows clients to navigate the API dynamically without prior knowledge of all endpoints.
  • Responses include links to related resources and actions that clients can perform next.

Key Advantages:

  • Improves API discoverability and usability.
  • Reduces client coupling to API structure, promoting flexibility and evolution.
  • Enables server-driven application state (clients follow links to discover and interact with resources).

Approach

We will create a RESTFUL API called gfg-wiki. We will insert articles and send HTTP requests. In this process, we will fetch, modify and delete articles. Robo3T will be used for the database. Postman will be used to send requests. In order to create a RESTFUL API in node.js, install :

  • node: A javaScript runtime environment, Download link: https://nodejs.org/en/download/
  • Robo3t: A MongoDB GUI. we will create a database using robo3t, Download link:  https://robomongo.org/
  • Postman: An API development and testing platform, Download link: https://www.postman.com/
  • Visual Studio Code or (any code editor), Download link: https://code.visualstudio.com/download
  • JSON viewer pro Chrome extension, Download link:  https://chromewebstore.google.com/detail/error

Steps for Installation

Step 1:  Initialize the NodeJS Project

Create a new directory, go to the terminal, and initialize NPM by running the following command .

npm init -y
πŸ‘ Image
Initialize npm 

Step 2: Install body-parser, mongoose, express 

  • body-parser: A middleware responsible for parsing the incoming request body before it can be handled.
  • express:  node.js framework
  • mongoose: Mongoose connects MongoDB to the Express web application
npm i body-parser mongoose express 

The updated dependencies in package.json file will look like:

"dependencies": {
"body-parser": "^1.20.2",
"express": "^4.19.2",
"mongoose": "^8.4.1",
}
πŸ‘ Image
Install packages 

Example: Implementation to show the above model with an example.

Step 4: Creating a database on Robo3T.

Consider a database of articles with a title and content.  

{ "title" : "gfg", "content" : "GeeksforGeeks is a computer science portal for geeks. " } { "title" : "REST", "content" : "REST stands for REpresentational State Transfer. " { "title" : "API", "content" : "Application Programming Interface" } { "title" : "richardson-model", "content" : " Grades APIs based on their adherence to REST constraints" } { "title" : "Http", "content" : "Hypertext Transfer Protocol (HTTP) is a protocol used to transfer hypermedia documents. " }
  • Go to Robo3t and create a new connection.
  • Create a database named gfg-wiki by clicking on the new connection button .
  • A database 'gfg-wiki' will be created. Now click on it and create a new collection called 'articles'
  • To insert documents, click on articles and select insert document.
  • Copy each document from above and insert it one by one.
  • To view all the documents, click on articles.

As you can see, the database looks like this:

πŸ‘ Image
database of articles 

The following shows how to create a database and insert documents. 

Step 5: Set up MongoDB

Set up MongoDB and write the schema for our articles to create models. To set up MongoDB, we will use mongoose. We will connect our application to the MongoDB location and add the database name to the URL string. By default, MongoDB uses port 27017.

mongoose.connect("mongodb://localhost:27017/gfg-wiki", {useNewUrlParser: true});

Schema defines the structure of our collection. We will create a schema named articleSchema consisting of two fields - title and content of the article

const articleSchema = {
title: String,
content: String
};

Now we will create a model from the articleSchema 

const Article = mongoose.model("Article", articleSchema);

Add the following code to your existing code in the app.js file. 

Step 6: Accessing all the articles

Accessing all the articles using the GET method. We can fetch all the articles by sending a get request by specifying the route of the resource and a callback function that handles the request. 

app.get(route, (req,res)=>{
})

To retrieve all the articles, we have to find the articles and read them from the database. 

<ModelName>.find({conditions},function(err,results){
//using the result
});

Add the following code to your existing app.js file. 

Start your application by running the following command 

node app.js

Output: We can access the articles at localhost:3000/articles. 

Step 7: Create a new article

Create a new article using the POST method. We will create a new article that will be added to the database. Here, the client sends data to the server.

We don't have a front-end yet, but we do have a server that has access to our database. We will test our API using Postman, rather than creating a form or a front end. Our goal is to send a post request to our server.

We will use the post method: 

app.post(route,(req,res)=>{
...
})

Once the client sends the post request we need to grab that data by req.body. 

Head over to postman and send a post request to localhost:3000/articles. Under the body tab, change the encoding to form-url coding, and add the title and content in key, along with the value that represents the data that we want to send along with the request. 

KeyValue
titlehttp verbs
contentThe most common HTTP verbs are POST, GET, PUT, PATCH, and DELETE. 

We need to save this article in our database.

const <constantName>=new <ModelName>({
<fieldName>:<fielddata>,..
});

Add the following code to the previous code in the app.js file 

Restart your server and send a post request using postman. 

Output: Go to Robo3T and refresh your collection to view the added article. Now we have an extra entry. 

Step 8: Fetching a specific article.

We will read a specific article from our database using the findOne method.

 <ModelName>.findone({conditions},(req,res)=>{
});

here, we will fetch the article with a title REST 

Add the following code to your app.js file. 

Output:   We will specify the article title in the URL and the article whose title matches that will be displayed. 

Step 9: Overwriting an article with the PUT method. 

We want to submit a new version of an article. To replace an existing article, we will send a put request. 

app.put(route ,(req,res)=>{
...
});

We will update the article using the Mongoose update method.

The overwrite specifies that we want to replace the entire article.  

<ModelName>.update(
{conditions},
{updates},
{overwrite:true}
(err,results)=>{
})

Add the following code to your app.js file 

In this case, we will change our title from API to Postman, and its content from Application Programming Interface to Postman is an API platform.

title: Postman
content: Postman is an API platform

By sending a put request to the route localhost:3000/articles/API  If the server finds a parameter with a title of API, it will replace the title with a new title and the content with a new one.

Step 9:  Updating an article using the PATCH method. 

We will update an existing article by sending a Patch request with the title of the article we wish to update. To update the article, we must give the fields we want to change in the body tab.

Now that we are changing only one field of an article rather than the entire article, the overwrite method is not needed when we call the update method to update our database. To update the article, we must give the fields we want to change in the body tab. 

Add the following code in your app.js file to modify the article. 

Output: It Updates only the fields that we provide. The title of the article REST is updated to Restful. 

Step 10: Deleting all the articles using the DELETE method

To delete all the articles from our database we will use deleteMany mongoose method and send a delete request from the postman. 

Add the following code to your app.js file 

Output:  We will send a delete request to localhost:3000/articles to remove all our articles. Visit Robo3T and refresh your collection. If we send a delete request from our postman, we will not observe any articles. 

The final app.js file: 

Comment

Explore