Example of a RESTful API built with Node.js, Express.js, Mongoose and MongoDB.
Get all items.
- Method:
GET
- URL:
/api/items
Create a new item.
- Method:
POST
- URL:
/api/items
- Body:
{
"id": "1",
"name": "React.js Essentials",
"description": "A fast-paced guide to designing and building scalable and maintainable web apps with React.js.",
"quantity": "10"
}
Get item with specific id.
- Method:
GET
- URL:
/api/items/1
Update entire item with specific id.
- Method:
PUT
- URL:
/api/items/1
- Body:
{
"id": "1",
"name": "React.js Essentials",
"description": "A fast-paced guide to designing and building scalable and maintainable web apps with React.js.",
"quantity": "20"
}
Update part of the item with specific id.
- Method:
PATCH
- URL:
/api/items/1
- Body:
{
"quantity": "30"
}
Delete item with specific id.
- Method:
DELETE
- URL:
/api/items/1
npm install
- Make sure MongoDB is running, if not:
sudo ~/mongodb/bin/mongod
(assuming you have~/mongodb
directory). npm run start