netlify-functions-simple-return

1.0.0 • Public • Published

Netlify Functions Simple Return

To return JSON from a Netlify Function, you have to return a statusCode as well as a JSON string (not JSON directly). This is a little inconvenient, so this packages simplifies the return so that you don't have to stringify the JSON directly.

How to Use

Instead of this...

exports.handler = () => {
    return {
        statusCode: 200,
        body: JSON.stringify({ msg: 'Hello World' }),
    };
};

Do this...

const simpleReturn = require('netlify-functions-simple-return');
exports.handler = () => {
    return simpleReturn(200, { msg: 'Hello World' });
};

This becomes more helpful as you add more potential returns in your Serverless Function.

Readme

Keywords

Package Sidebar

Install

npm i netlify-functions-simple-return

Weekly Downloads

5

Version

1.0.0

License

ISC

Unpacked Size

1.21 kB

Total Files

3

Last publish

Collaborators

  • jamesqquick