Last active
August 19, 2020 07:49
-
-
Save bastienapp/aba711f5d512c85a8eef79b7e9dffe97 to your computer and use it in GitHub Desktop.
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 app = express(); | |
const port = 3000; | |
app.get('/api/movies', (req, res) => { | |
res.send('Récupération de tous les films'); | |
}); | |
app.get(`/api/movies/:id`, (req, res) => { | |
const id = req.params.id; // récupère John | |
res.json({ id: id}); | |
}); | |
app.get(`/api/employee`, (req, res) => { | |
const name = req.query.name; | |
if (name !== undefined) { | |
res.status(404).send(`Impossible de récupérera l'employé ${name}`); | |
} else { | |
res.sendStatus(304); | |
} | |
}); | |
app.listen(port, (err) => { | |
if (err) { | |
throw new Error('Something bad happened...'); | |
} | |
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