pambda-json-api
Pambda for JSON API.
Installation
npm i pambda-json-api
Usage
const compose createLambda = ;const router = ;const jsonApi = ;const handler =;
jsonApi(options)
options.reqJsonOnly
- The boolean value on whether to accept a JSON request only.
If true, an error occurs for requests that
Content-Type
is notapplication/json
. - The default value is true.
- The boolean value on whether to accept a JSON request only.
If true, an error occurs for requests that
options.resJsonOnly
- The boolean value to whether to return a JSON response only.
If true, call
JSON.stringify()
and setContent-Type
. - The default value is true.
- The boolean value to whether to return a JSON response only.
If true, call
options.errorHandler
- The function with argument
(err, event, context, callback)
, called when an error occurs. - The default is to return Internal Server Error.
- The function with argument
When receiving a JSON request, set the result of parsing JSON to event.body
. Subsequent Pambda can use parsed body
.
Also, if necessary, return body
as a JSON string for the result that subsequent Pambda passes to callback
.
License
MIT