JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1776
  • Score
    100M100P100Q120184F
  • License ISC

Hapi plugin to bring back qs support

Package Exports

  • hapi-qs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hapi-qs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Hapi QS

Build Status

Hapi plugin that brings back qs support for Hapi 12. Qs support has been removed from Hapi 12 (https://github.com/hapijs/hapi/issues/2985), this plugin aims to bring it back.

Install

npm install hapi-qs

Usage

  const server = new Hapi.Server();

  server.connection({ port: port });

  \\...

  server.register({
      register: require('hapi-qs'),
      options: {} /* optional */
    },
    err => {
      \\...
    });

  \\...

Parsing query

  server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {
      return reply(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: function (request, reply) {
      return reply(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