Skip to content

Instantly share code, notes, and snippets.

@jervalles
Last active November 19, 2019 10:48
Show Gist options
  • Save jervalles/c9f9ef06acdf240cc8e7c9ab52d553d8 to your computer and use it in GitHub Desktop.
Save jervalles/c9f9ef06acdf240cc8e7c9ab52d553d8 to your computer and use it in GitHub Desktop.
Express quest 1
const express = require("express");
const app = express();
const port = 3000;
app.get(`/`, (request, response) => {
response.send("Bienvenue sur Express");
});
app.get(`/api/movies`, (request, response) => {
response.send("Récupération de tous les films");
});
app.get(`/api/movies/:id`, (request, response) => {
response.json({ id: request.params.id });
});
app.get(`/api/employee`, (request, response) => {
const name = request.query.name;
if (name) {
response.status(404).send(`Impossible de récupérer l'employé ${name}`);
} else {
response.sendStatus(304);
}
});
// http://localhost:3000/api/employee?name=test (for test)
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