Video 92: Resource Reading Endpoints: Part II
This commit is contained in:
parent
ff4ec82ef5
commit
b4f47db7ab
@ -50,6 +50,28 @@ app.post('/tasks', (req, res) => {
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/tasks', (req, res) => {
|
||||
Task.find({}).then((tasks) => {
|
||||
res.send(tasks)
|
||||
}).catch((e) => {
|
||||
res.status(500).send()
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/tasks/:id', (req, res) => {
|
||||
const _id = req.params.id
|
||||
|
||||
Task.findById(_id).then((task) => {
|
||||
if (!task) {
|
||||
return res.status(404).send()
|
||||
}
|
||||
|
||||
res.send(task)
|
||||
}).catch((e) => {
|
||||
res.status(500).send()
|
||||
})
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log('Server is up on port ' + port)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user