A REST Express API, has various endpoints that perform CRUD operations on a Mongo Database, using the REST standards . It has two data models and two routers : clothes and food .
Ahmad Arman
(.env)
file
PORT = 3000
MONGOOSE_URI = mongodb://localhost:27017/people
MONGOOSE_TEST_URI = mongodb://localhost:27017/testing
- Install the following dependencies
npm init -y
npm i cors dotenv express morgan mongoose
npm i -D jest supertest
npm i @code-fellows/supergoose
mongod --dbpath=/Users/path/to/data/db
- clone the repo.
- Enter the command
npm start
- Use endpoints :
- Method : GET
- CRUD Operation : Read / Gets All Food Records
- Response Body : JSON
[
{
"_id": "60a59fe36c328241b96f7237",
"name": "burger",
"role": "meat",
"__v": 0
},
{
"_id": "60a5a0156c328241b96f7238",
"name": "pizza",
"role": "chicken",
"__v": 0
}
]
- Method : POST
- CRUD Operation : Create / Add a Record
- Response Body : JSON
{
"_id": "60a5938ee109aa218e6f5a6f",
"name": "pizza",
"type": "chicken",
"__v": 0
}
- Method : GET
- CRUD Operation : Read / Get One Record
- Response Body : JSON
{
"_id": "60a5938ee109aa218e6f5a6f",
"name": "pizza",
"type": "chicken",
"__v": 0
}
- Method : PUT
- CRUD Operation : UPDATE / Update a Record
- Response Body : JSON
{
"_id": "60a5938ee109aa218e6f5a6f",
"name": "pizza",
"type": "chicken",
"__v": 0
}
- Method : DELETE
- CRUD Operation : DELETE / Delete a Record
- Response Body : JSON
{
"_id": "60a5938ee109aa218e6f5a6f",
"name": "pizza",
"type": "chicken",
"__v": 0
}
- Method : GET
- CRUD Operation : Read / Gets All clothes Records
- Response Body : JSON
[
{
"_id": "60a5938ee109aa218e6f5a6f",
"name": "jacket",
"type": "kids",
"__v": 0
},
{
"_id": "60a5945ce109aa218e6f5a70",
"name": "jacket",
"type": "man",
"__v": 0
}
]
- Method : POST
- CRUD Operation : Create / Add a Record
- Response Body : JSON
{
"name":"jacket",
"type":"man"
}
- **Method** : GET - **CRUD Operation** : Read / Get One Record - **Response Body** : JSON ``` { "_id": "60a5938ee109aa218e6f5a6f", "name": "jacket", "type": "man", "__v": 0 } ```
- Method : PUT
- CRUD Operation : UPDATE / Update a Record
- Response Body : JSON
{
"_id": "60a5938ee109aa218e6f5a6f",
"name": "jacket",
"type": "mannn",
"__v": 0
}
- Method : DELETE
- CRUD Operation : DELETE / Delete a Record
- Response Body : JSON
{
"_id": "60a5938ee109aa218e6f5a6f",
"name": "jacket",
"type": "mannn",
"__v": 0
}
- Test .
- There's 2 test files . logger.test.js and server.test.js
- In terminal run :
npm test