Created
March 29, 2020 15:26
-
-
Save lebowvsky/216834f411a83a1f6e7af3e95386f70e to your computer and use it in GitHub Desktop.
Express1 - Découverte d'Express
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; | |
app.get('/api/movies', (req, res) => { | |
res.send('Récupération de tous les films'); | |
}); | |
app.get('/api/movies/:id', (req, res) => { | |
const idMovie = req.params.id; | |
res.json({id: idMovie}); | |
}); | |
app.get('/api/employee', (req, res) => { | |
const name = req.query.name; | |
if(!name){ | |
res.sendStatus(304); | |
} else { | |
res.status(404).send(`Impossible de récupérer l'employé : ${name}`); | |
} | |
}); | |
app.listen(port, (err) => { | |
if(err){ | |
throw new Error('Something goes wrong'); | |
} else { | |
console.log(`Server is listen on the port : ${port}`); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment