“Params Express JS” Réponses codées

Params Express JS

app.get('/path/:name', function(req, res) { // url: /path/test
  console.log(req.params.name);  // result: test
});

// OR

app.get('/path', function(req, res) {  // url: /path?name='test'
  console.log(req.query['name']);  // result: test
});
Ham-Solo

Express Get Params après?

GET /something?color1=red&color2=blue

app.get('/something', (req, res) => {
    req.query.color1 === 'red'  // true
    req.query.color2 === 'blue' // true
})

req.params refers to items with a ':' in the URL and req.query refers to items associated with the '?
Batman

Express Get URL Paramètres

app.get('/path/:name', function(req, res) {
  res.send("tagId is set to " + req.params.name);
});
Batman

Param exprime dans l'URL

app.get('/p/:tagId', function(req, res) {
  res.send("tagId is set to " + req.params.tagId);
});

// GET /p/5
// tagId is set to 5
SirSundays

Node Express Params

// url = /something/2?color1=red&color2=blue&type=square

app.get('/something/:id', (req, res) => {
  	req.params.id  === 2 // true
    req.query.color1 === 'red'  // true
    req.query.color2 === 'blue' // true
    req.query.type === 'square' // true
})
miletoo

Réponses similaires à “Params Express JS”

Questions similaires à “Params Express JS”

Plus de réponses similaires à “Params Express JS” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code