1.0.0 • Published 4 years ago
netlify-functions-simple-return v1.0.0
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.
1.0.0
4 years ago