@sigfox/koa-query-fields

1.0.1 • Public • Published

koa-query-fields

Koa middleware selecting fields from ctx.body depending on ctx.query.fields.

When use it?

This module can be used if you need to select fields from the response body of a koa request depending on ctx.query.fields

Features

Select response body fields, the middleware expects to find state.query.fields.

Install

npm install @sigfox/koa-query-fields

Usage

const Koa = require('koa');
const Router = require('koa-router');
const { asyncGetPublicData } = require('hypothetical-async-getters');
const queryFields = require('@sigfox/koa-query-fields');

const getRoutes = () => {
  const router = new Router();

  router.get('data', queryFields, async ctx => {
    const data = await asyncGetPublicData();
    ctx.body = data;
  });

  return router.routes();
};

const app = new Koa().use(getRoutes()).listen();

Test

npm test

Licence

This project is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i @sigfox/koa-query-fields

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

5.96 kB

Total Files

5

Last publish

Collaborators

  • robnriks
  • cgrimal
  • damien-s
  • lbdremy