This package helps to build json response from server side. This will be specially helpfull in serverless environments.
npm i json-response-builder
import {res} from "json-response-builder"
# returns a json body
return res.json({
"key":"value" //JSON BODY HERE
})
This would output a response as bellow
{
headers: { 'content-type': 'application/json' },
statusCode: 400,
isBase64Encoded: false,
body: '{"key":"value"}'
}
Can include additional headers and options as below
import {res} from "json-response-builder"
res
.json({
"key": "value",
})
.headers({
"headerKey":"headerValue"
})
.gzip() //apply gzip compression
.statusCode(400)
.build()
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.