Created
November 29, 2019 16:30
-
-
Save clarade/87a8d199b92ca8d580c40f7147578744 to your computer and use it in GitHub Desktop.
Testing req and res on Express
This file contains 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.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