SHARE
TWEET

Untitled

a guest May 25th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const app = express();
  3. const port = 3000;
  4.  
  5. app.get('/', (req, res) => {
  6.   res.send('Bienvenue sur Express');
  7. });
  8.  
  9. app.get('/api/movies', (req,res) => {
  10.     res.send('Récupération de tous les films');
  11. });
  12.  
  13. app.param('id', (req, res, next, id) => {
  14.     req.id = id;
  15.     next();
  16. });
  17.  
  18. app.get('/api/movies/:id', (req,res) => {
  19.     const data = {
  20.         id : req.id
  21.     }
  22.     res.json(data);
  23. });
  24.  
  25. app.get('/api/employee/', (req, res) => {
  26.     let name = req.query.name;
  27.  
  28.     if (!name)
  29.         res.status(304).end();
  30.  
  31.     else {
  32.         res.status(404).send(`Impossible de récupérer l\'employé ${name}`);
  33.     }
  34. });
  35.  
  36. app.listen(port, (err) => {
  37.   if (err) {
  38.     throw new Error('Something bad happened...');
  39.   }
  40.  
  41.   console.log(`Server is listening on ${port}`);
  42. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top