Created
May 22, 2019 15:21
-
-
Save santiagocodes/7c1e7673037ba6d73418671e55154946 to your computer and use it in GitHub Desktop.
Express Quest 1- Express Discovery
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; | |
//Quest- You will create some GET routes on your server: | |
//1.1 A route answering the url /api/movies which | |
//sends as information a string containing "All films" | |
app.get(`/api/movies`, (req, res) => { | |
res.send("All films"); | |
}); | |
//1.2 A route that responds to the url /api/movies/\<movie id\> that | |
//sends as information a JSON object containing {id: \<movie id\>} | |
app.get(`/api/movies/:movieId`, (req, res) => { | |
res.json({id: req.params.movieId}); | |
}); | |
//1.3 A route responding to the /api/employee/ url that | |
//sends a status 304 | |
app.get(`/api/employee/`, (req, res) => { | |
res.sendStatus(304); | |
}); | |
//1.4 A route responding to the url /api/employee?name=\<employee name\> which </employee> | |
//sends a status 404 | |
//with a string containing "Unable to retrieve employee" <name of employee the employee \> " | |
app.get(`/api/employee`, (req, res) => { | |
let name = req.query.name | |
res.status(404).send("Unable to retrieve employee " + name ); | |
}); | |
app.listen(port, () => console.log(`Listening in port ${port})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment