Skip to content

dafortune/hapi-qs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hapi QS

Build Status

Hapi plugin that brings back qs support that was removed in Hapi 12 (hapijs/hapi#2985).

hapi-qs v1.1.3 is for Hapi v12 to v16. hapi-qs v2+ support Hapi v17 only.

Install

npm install hapi-qs

Or for pre-Hapi 17:

npm install [email protected]

Usage

const server = new Hapi.Server();

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

Parsing query

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

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)
  • queryString (default true): whether to parse query string
  • 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

Stars

Watchers

Forks

Packages

No packages published