What is a REST API and how is it used in MEAN stack?
What is a REST API and how is it used in MEAN stack?
193
07-Apr-2025
Updated on 29-Apr-2025
Khushi Singh
29-Apr-2025A REST API (Representational State Transfer Application Programming Interface) refers to a web service architecture that employs HTTP to exchange data based on statelessness and resources architecture. In REST, data is treated as resources, for example, users, products, etc., while operations are performed under the commonly used methods to handle resources over HTTP: GET (Read), POST (Create), PUT/PATCH (Update) and DELETE (Delete).
Among the four components of the MEAN stack (MongoDB, Express.js, Angular, Node.js), this is where REST API serves to connect the latter two—Angular and Node.js/Express.js— with the data storage MongoDB.
Here is the way this stack fits into the MEAN structure:
Frontend (Angular): Sends HTTP requests to specific API endpoints created in the backend. For instance, Angular may use a GET request to request users from the /api/users endpoint.
Backend (Node.js + Express.js): Receives these requests through defined routes, processes them (e.g., retrieving or updating data), and sends back appropriate responses. Express.js can be used to create routes for handling APIs in the RESTful manner in Node.js.
Database (MongoDB): Acts as the data store. In the backend development, MongoDB queries either through Mongoose or is used to fetch or modify data according to the API request made.
For example, when a user fills a form in the Angular application, the form uses a POST request to send information to the REST API; it then stores the data in MongoDB. The success message or the saved object can be returned by the API.
This makes the MEAN stack applications to have an architectural design of REST APIs in a clean way of scenario known as separation of concerns, hence scalability.