Wondering what’s next for npm?Check out our public roadmap! »

    @middy/http-partial-response
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.1 • Public • Published

    Middy http-partial-response middleware

    Middy logo

    HTTP partial response middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda

    Filtering the data returned in an object or JSON stringified response has never been so easy. Add the httpPartialResponse middleware to your middleware chain, specify a custom filteringKeyName if you want to and that's it. Any consumer of your API will be able to filter your JSON response by adding a querystring key with the fields to filter such as fields=firstname,lastname.

    This middleware is based on the awesome json-mask package written by Yuriy Nemtsov

    Install

    To install this middleware you can use NPM:

    npm install --save @middy/http-partial-response

    Options

    This middleware does not have any option

    Sample usage

    import middy from '@middy/core'
    import httpPartialResponse from '@middy/http-partial-response'
    
    const handler = middy((event, context) => {
      const response = {
        statusCode: 200,
        body: {
          firstname: 'John',
          lastname: 'Doe',
          gender: 'male',
          age: 30,
          address: {
            street: 'Avenue des Champs-Élysées',
            city: 'Paris'
          }
        }
      }
    
      return response
    })
    
    handler.use(httpPartialResponse())
    
    const event = {
      queryStringParameters: {
        fields: 'firstname,lastname'
      }
    }
    
    handler(event, {}, (_, response) => {
      expect(response.body).toEqual({
        firstname: 'John',
        lastname: 'Doe'
      })
    })

    Middy documentation and examples

    For more documentation and examples, refers to the main Middy monorepo on GitHub or Middy official website.

    Contributing

    Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.

    License

    Licensed under MIT License. Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the Middy team.

    FOSSA Status

    Install

    npm i @middy/http-partial-response

    DownloadsWeekly Downloads

    306

    Version

    2.0.1

    License

    MIT

    Unpacked Size

    7.17 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar