Last active
July 1, 2019 09:56
-
-
Save evadav/7308f44f92a1ae7c02856cd3b31eb331 to your computer and use it in GitHub Desktop.
Express 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; | |
//A route answering the url /api/movies which sends as information a string containing "All films" | |
app.get('/api/movies' , function(req, res ){ | |
response.end('All movies'); | |
}); | |
//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',function(req, res) { | |
res.json({params: req.params, query: req.query}); | |
}); | |
//A route responding to the /api/employee/ url that sends a status 304 | |
app.get('/api/employee/', function(req, res,next){ | |
res.Status(304); | |
if(req.query.name)next () | |
else res.end(); | |
}); | |
//A route responding to the url _/api/employee?name=\<employee name\> _ which sends a status 404 with a string containing "Unable to retrieve employee" <name of employee the employee \> " | |
app.get('/api/employee', function (req, res) { | |
res.status(404); | |
res.send('Unable to retrieve'+ req.query.name); | |
}); | |
app.listen(port, function() { | |
// 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