Edit Page

req.param()

Returns the value of the parameter with the specified name.

Usage

#
req.param(name[, defaultValue]);

Details

#

req.param() searches the URL path, body, and query string of the request (in that order) for the specified parameter. If no parameter value exists anywhere in the request with the given name, it returns undefined or the optional defaultValue if specified.

Example

#

Consider a route (POST /product/:sku) that points to a custom action or policy that has the following code:

req.param('sku');
// -> 123

We can get the expected result by sending the sku parameter any of the following ways:

Notes

#
  • The order of precedence means that URL path params will override request body params, which will override query string params.
  • If you'd like to get ALL parameters from ALL sources (including the URL path, query string, and parsed request body) you can use req.allParams().

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

Reference