Which is the structure of the path in the case of query request?

I'm using hapi.js but one thing is not clear for me. In the case I make api request passing params in the path, I could get these ones by calling request.params in the handler. When I do request in the form of query what should be the path? In the first case I place in the path property something like /{param} but in the second one?

You can use request.query. Four properties hold request data:

  • headers: the raw request headers (references request.raw.headers).
  • params: an object where each key is a path parameter name with matching value.
  • payload: the request payload based on the route payload.output and payload.parse settings.
  • query: an object containing the query parameters.

You can find more information in the API Reference.

Edit: Here is an example:

var Hapi = require('hapi');
var server = new Hapi.Server(3000);

server.route({
  method: 'GET',
  path: '/',
  handler: function (request, reply) {
    console.log(request.query.example);
  }
});

server.start(function () {
  console.log('Server running at:', server.info.uri);
});

If you visit http://localhost:3000/?example=hapi, it will log hapi to the console.