1
0
Fork 0

Video 91: Resource Reading Endpoints: Part I

This commit is contained in:
JayWll 2020-02-23 15:23:38 -07:00
parent f550158865
commit ff4ec82ef5
1 changed files with 22 additions and 0 deletions

View File

@ -18,6 +18,28 @@ app.post('/users', (req, res) => {
})
})
app.get('/users', (req, res) => {
User.find({}).then((users) => {
res.send(users)
}).catch((e) => {
res.status(500).send()
})
})
app.get('/users/:id', (req, res) => {
const _id = req.params.id
User.findById(_id).then((user) => {
if (!user) {
return res.status(404).send()
}
res.send(user)
}).catch((e) => {
res.status(500).send()
})
})
app.post('/tasks', (req, res) => {
const task = new Task(req.body)