npm install responseasy --save
👌 An easy, simple and elegant http response builder for aws lambda functions with proxy integration.
Built with ❤
When working with pure aws lambda functions and proxy integration is always necessary to JSON.stringify payload, manipulate headers, status code and formatting response, which is verbose and nothing clean.
ResponsEasy is an easy, simple and elegant http response builder for aws lambda functions with proxy integration.
This package is intended for server side use only.
npm install responseasy --save
Initializing ResponsEasy with default headers:
const res = require('responseasy')({
headers: { // <-- Default headers
'X-Content-Type-Options': 'nosniff',
'X-XSS-Protection': '1; mode=block',
'Pragma': 'no-cache',
'Cache-Control': 'no-store'
}
})
Returning 200 - OK
using named getter ok
:
const response = res.ok.json({ name: 'Luiz' })
/*
{
statusCode: 200,
body: '{"name":"Luiz"}',
headers: {
'X-Content-Type-Options': 'nosniff',
'X-XSS-Protection': '1; mode=block',
Pragma: 'no-cache',
'Cache-Control': 'no-store'
}
}
*/
Returning 400 - Bad Request
using named getter badRequest
:
const response = res.badRequest.json({ error: true })
/*
{
statusCode: 400,
body: '{"error":true}',
headers: {
'X-Content-Type-Options': 'nosniff',
'X-XSS-Protection': '1; mode=block',
Pragma: 'no-cache',
'Cache-Control': 'no-store'
}
}
*/
Returning by a custom status code:
const response = res.status(202).json({ id: '1863b459-bebb-4d18-9de5-b6ea857f1627' })
/*
{
statusCode: 202,
body: '{"id":"1863b459-bebb-4d18-9de5-b6ea857f1627"}',
headers: {
'X-Content-Type-Options': 'nosniff',
'X-XSS-Protection': '1; mode=block',
Pragma: 'no-cache',
'Cache-Control': 'no-store'
}
}
*/
Made with ❤