Created
June 10, 2020 14:36
-
-
Save clemderome/11e3b3e351901c2717fa3936695f2090 to your computer and use it in GitHub Desktop.
Express 4 PUT
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
const express = require('express'); | |
const connection = require('./conf'); | |
const app = express(); | |
const port = 3000; | |
app.use(express.json()); | |
app.use(express.urlencoded({ | |
extended: true | |
})); | |
app.put('/api/movie/:id', (req, res) => { | |
const idMovie = req.params.id; | |
const formData = req.body; | |
connection.query('UPDATE movie SET ? WHERE id = ?', [formData, idMovie], err => { | |
if (err) { | |
console.log(err); | |
res.status(500).send("Erreur lors de la modification d'un film"); | |
} else { | |
res.sendStatus(200); | |
} | |
}); | |
}); | |
app.listen(port, (err) => { | |
if (err) { | |
console.error('Something bad happened'); | |
} else { | |
console.log(`server is listening on ${port}`); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment