MongoDB Rest API
MongoDB Rest API
JavaScript is considered the top web development language today, running in millions of
applications and websites. One of the building blocks for the JavaScript stack, on many of its
variations, is REST API-based communication between the front-end and back-end tiers.A
popular way of implementing the REST API approach uses Express JS as the back-end web
server and MongoDB as the document store. This concept easily maps MongoDB’s document
model to the REST API payloads which are JSON by nature.
API mean Application Programming Interface, which is a set of clearly defined methods of
communication between the frontend and the database.
REST which stands for Representational State Transfer, is an architectural style for providing
standards between computer systems on the web, making it easier for systems to communicate
with each other.
REST APIs mostly use JSON as the preferred choice for transferring data as they are easy to
understand and is readable.
In this experiment, we will be using Node, Express and MongoDB to create a REST API that
would support the four operations — GET, POST, PUT and DELETE.
So, let’s first discuss these four operations and try to understand what they actually mean in the
context of API development.
GET — GET means to read the data. The function of this operation is to retrieve the data from
the database and present it to the user.
POST — POST, as the name suggests, is used to post/add new data to the database. It allows
users to add new data to the database.
PUT — PUT means to update the data already present in the database.
DELETE — It is used to delete any existing data from the database.
So, our REST API will perform all these operations. We will use the Express package to make
our work easier. We will use MongoDB as the NoSQL database to store all our data. So, we
will do it step by step. First, we would build the API endpoints and then we would connect to
Program
//retrieve from DB
app.get("/get_users", async(req,res) =>{
try {
});
mongoose.connect("mongodb+srv://admin:admin123@cluster0.d1h2r.mongodb.net/testdb?re
Department of Information Technology | APSIT
PARSHVANATH CHARITABLE TRUST'S