Skip to content

Instantly share code, notes, and snippets.

@bastienapp
Last active August 19, 2020 07:49
Show Gist options
  • Save bastienapp/aba711f5d512c85a8eef79b7e9dffe97 to your computer and use it in GitHub Desktop.
Save bastienapp/aba711f5d512c85a8eef79b7e9dffe97 to your computer and use it in GitHub Desktop.
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