Skip to content

isabella232/hapi-qs

 
 

Repository files navigation

Hapi QS

Hapi plugin that adds qs support for form data in hapi 18. Fork of hapi-qs.

Install

npm install @lob/hapi-qs

Hapi 18+

As of Hapi 18, there is built-in support for providing a query string parser, but there is still a need for parsing form payloads.

Usage

const server = new Hapi.Server();

await server.register({
  plugin: require('hapi-qs'),
  options: {} /* optional */
});

Parsing payload

Payload will only be parsed if content-type is set to a kind of x-www-form-urlencoded or multipart/form-data

  server.route({
    method: 'POST',
    path: '/',
    handler: (request, h) => {
      return request.payload; // request.query constains the parsed values
    }
  });

Options

  • qsOptions (default undefined): This object is past directly to Qs parse method (more info)
  • payload: whether to parse payload (it is valid only when content-type header is a kind of x-www-form-urlencoded or multipart/form-data)

Running tests

  npm test

About

Bring back qs support for hapi 12

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%