https://github.com/aishanipach/restful-api
Express & Node.js to create a sleek CRUD RESTful API.
https://github.com/aishanipach/restful-api
api api-rest beginner-friendly beginner-project database express mongodb mongodb-atlas mongoose nodejs nodejs-api web-application
Last synced: 3 months ago
JSON representation
Express & Node.js to create a sleek CRUD RESTful API.
- Host: GitHub
- URL: https://github.com/aishanipach/restful-api
- Owner: Aishanipach
- Created: 2023-05-18T14:11:30.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-18T17:29:00.000Z (over 1 year ago)
- Last Synced: 2025-03-16T06:45:04.325Z (7 months ago)
- Topics: api, api-rest, beginner-friendly, beginner-project, database, express, mongodb, mongodb-atlas, mongoose, nodejs, nodejs-api, web-application
- Language: JavaScript
- Homepage:
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RESTful-API
Express & Node.js to create a sleek CRUD RESTful API. Models for payload validation to casually throw 400 client side errors💁♀️
     
## What is difference between req.query & req.params in mongoose controllers?
.params only get the route parameters while .query gets query strings passed.
### .query
GET localhost:3000/contact/contactId/?contactId=_(Id)_
crmRoutes.js
```
app.route("/contact/contactId")
.get(getContactById)
```crmControllers.js
```
export const getContactById = (req, res) => {
const Id = req.query.contactId
console.log(Id)
const name = req.query.fname
Contact.findById(Id).then(contact => res.json(contact)).catch(err => (console.log(err)));
}
```### .params
GET localhost:3000/contact/_(Id)_
crmRoutes.js
```
app.route("/contact/:contactId")
```crmControllers.js
```
export const getContactById = (req, res) => {
const Id = req.params.contactId
console.log(Id)
Contact.findById(Id).then(contact => res.json(contact)).catch(err => (console.log(err)));
}```
### Resources:
1. https://mongoosejs.com/docs/tutorials/findoneandupdate.html
2. https://www.geeksforgeeks.org/mongoose-findoneandupdate-function/