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

    create-response-object

    1.1.0 • Public • Published

    create-response-object

    NPM Module. A very, very tiny object creator for lambda-proxy responses. Primarily for 200 and 400 responses with an optional message. Also supports 301 and 302 responses with redirect URI.

    Install

    npm install --save create-response-object

    Usage

    createResponseObject('200','Hello world!');

    Options

    • code: (optional) The HTTP status code to return. Defaults to '200'.
      {string} '200', '301', '302', '400', etc.
    • message: (optional) The response body's message.
      {string} 'Hello World'.
    • uri: (required for 301|302) The redirect uri.

    Example

    const createResponseObject = require('create-response-object');
     
    exports.handler = async (event, context) => {
      return await createResponseObject('200','Hello World!');
      // or
      // return await createResponseObject('400','Something went wrong!');
      // or
      // return await createResponseObject('301','','https://www.npmjs.com/package/create-response-object');
    };

    Will output:

    {
        "statusCode": "200",
        "body": "Hello World!",
        "headers": {
            "Content-Type": "application/json"
        }
    }

    Credit

    This function, as small as it is, draws inspiration from jroberson.

    Install

    npm i create-response-object

    DownloadsWeekly Downloads

    0

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    4.71 kB

    Total Files

    4

    Last publish

    Collaborators

    • avatar