Skip to content

Instantly share code, notes, and snippets.

@clarade
Created November 29, 2019 16:30
Show Gist options
  • Save clarade/87a8d199b92ca8d580c40f7147578744 to your computer and use it in GitHub Desktop.
Save clarade/87a8d199b92ca8d580c40f7147578744 to your computer and use it in GitHub Desktop.
Testing req and res on Express
const express = require("express");
const app = express();
const port = 3000;
app.listen(port, err => {
if (err) {
throw new Error("Something bad happened...");
}
console.log(`Server is listening on ${port}`);
});
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;
res.json({ id: id });
});
app.get("/api/employee", (req, res) => {
const name = req.query.name;
res.status(404).send(`Impossible de récupérer l'employé ${name}`);
});
app.get("/api/employee/", (req, res) => {
res.status(304).end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment