1.0.9 • Published 2 years ago
json-response-builder v1.0.9
json-response-builder
This package helps to build json response from server side. This will be specially helpfull in serverless environments.
Installation
npm i json-response-builder
Simple Usage
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"}'
}
Options
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()
Contributing
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.