Created
June 2, 2020 19:10
-
-
Save Lio-code/a6196df3ef69fbae6d0c9c794f7b4f62 to your computer and use it in GitHub Desktop.
Lionel - Express 1 - 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('/', (request, response) => { | |
| response.send('Bienvenue sur Express'); | |
| }); | |
| app.get('/api/movies', (request, response) => { | |
| response.send('Récupération de tous les films'); | |
| }); | |
| app.get(`/api/movies/:id`, (request, response) => { | |
| const id = request.params.id; | |
| response.json({ id: id }); | |
| }); | |
| app.get(`/api/employee`, (request, response) => { | |
| const name = request.query.name; | |
| response.status(404).send(`Impossible de récupérer l'employé ${name}`) | |
| }); | |
| app.get('/api/employee', (request, response) => { | |
| response.status(304).end(); | |
| }); | |
| app.listen(port, (err) => { | |
| 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