This is an example of a simple crud application node js, express and mongodb
Create a simple express application that:
- Connects to a database
- Creates the payload: { message: String, data: Object } This means you are to return an object containing a message that tells the client if the request is successful or not, and data object containing your result. If there's an error in the request, the response should return the error message instead.
- Get's the data created
- Updates the data created
- Deletes the data created
The data you are required to create should contain name, email and country
Very important:
You are required to upload your application to github and host it on heroku. You are also required to create a simple documentation of your routes in your github readme file You are to submit your your github link with the hosted link in the readme file too
Hint:
Test your routes with postman. Ensure they work Deploying Node.js Apps on Heroku | Heroku Dev Center
- Clone the repo
OR
git clone https://github.com/Odumz/crudmongodbapp.git
git pull origin main https://github.com/Odumz/crudmongodbapp.git
- Install NPM packages
npm install || npm i
- Once in the root folder, run
npm run start
The postman collection can be imported at https://www.getpostman.com/collections/19425c4728c712fe1857
Local URL: http://localhost:5002
Production URL: https://polar-shelf-91739.herokuapp.com {URL}:
get:
summary: Test route to check connection
responses:
status: '200'
message: 'Welcome to my crud application with mongodb.'
{URL}/api/v1:
get:
summary: Test route to check connection
responses:
status: '200'
message: 'Welcome to the my crud application with mongo db. This is the profile service'
Get all route
{URL}/api/v1/profiles:
get:
summary: Route for getting all records
responses:
status: '200'
message: {
message: {String: 'All profiles successfully fetched'},
profile: {Object: {_id, name, email, country}}
}
Get one route
{URL}/api/v1/profile/:id:
get:
summary: Route for getting a record by id
responses:
status: '200'
message: {
message: {String: 'Profile successfully fetched'},
profile: {Object: {_id, name, email, country}}
}
Create route
{URL}/api/v1/create:
post:
summary: Route for creating new records
responses:
status: '200'
message: {
message: {String: 'Profile successfully created'},
profile: {Object: {_id, name, email, country}}
}
body: {
option: raw,
payload: {
"name": "Antoinne Laporta",
"email": "juanlaporta@barcelona.fcb",
"country": "Argentina"
}
}
Edit route
{URL}/api/v1/edit/:id:
put:
summary: Route for editing a record
responses:
status: '200'
message: {
message: {String: 'Profile updated successfully'},
profile: {Object: {_id, name, email, country}}
}
body: {
option: raw,
payload: {
"name": "Antoinne Laporta",
"email": "juanlaporta@barcelona.fcb",
"country": "Argentina"
}
}
Delete route
{URL}/api/v1/delete/:id:
delete:
summary: Route for getting all records
responses:
status: '200'
message: {
message: {String: 'Profile deleted successfully'},
profile: {String: 'item no longer exists'}
}