Created
January 18, 2022 22:00
-
-
Save petrosDemetrakopoulos/c70e2cdd430621039c4bdd3b9bb09ac5 to your computer and use it in GitHub Desktop.
EthairBalloons API CRUD operations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/create', (req,res) => { | |
const newCarObject = req.body; | |
Car.save(newCarObject, function (err, objectSaved) { | |
if (!err) { | |
res.json(objectSaved); | |
} else { | |
res.send(err) | |
} | |
}); | |
}) | |
app.patch('/update/:id', (req,res) => { | |
const newCarObject = req.body; | |
Car.updateById(req.params.id, newCarObject, function (err, objectSaved) { | |
if (!err) { | |
res.json(objectSaved); | |
} else { | |
res.send(err) | |
} | |
}); | |
}) | |
app.get('/find', (req,res) => { | |
Car.find(function (err, allObjects) { | |
if (!err) { | |
res.json(allObjects); | |
} else { | |
res.send(err) | |
} | |
}); | |
}) | |
app.get('/find/:id', (req,res) => { | |
Car.findById(req.params.id, function (err, found) { | |
if (!err) { | |
res.json(found); | |
} else { | |
res.send(err) | |
} | |
}); | |
}) | |
app.delete('/delete/:id', (req,res) => { | |
Car.deleteById(req.params.id, function (err, found) { | |
if (!err) { | |
res.json({message: "Object deleted successfully"}); | |
} else { | |
res.send(err) | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment