Skip to content

Instantly share code, notes, and snippets.

@petrosDemetrakopoulos
Created January 18, 2022 22:00
Show Gist options
  • Save petrosDemetrakopoulos/c70e2cdd430621039c4bdd3b9bb09ac5 to your computer and use it in GitHub Desktop.
Save petrosDemetrakopoulos/c70e2cdd430621039c4bdd3b9bb09ac5 to your computer and use it in GitHub Desktop.
EthairBalloons API CRUD operations
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