netlify-functions-simple-return
v1.0.0
Published
This package simplifies the return value in a Netlify Function
Downloads
4
Readme
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.