
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
api-gateway-http-response
Advanced tools
A small library that generates API Gateway HTTP responses for Lambda proxy integration (ie. for CloudFormation and AWS SAM)
A small library that generates API Gateway HTTP responses for Lambda proxy integration. It can be used with AWS CloudFormation and AWS SAM.
This package exports a function that accepts four params and returns an object.
Function accepts following four params:
Response body (optional) - A string or an object that should be returned as a HTTP response from the API Gateway. Default value is an empty string.
Status code (optional) - A number that represents HTTP status code. Default values are:
Headers (optional) - An object with headers that will be passed as response headers. Default value is:
{
"Access-Control-Allow-Headers": "Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token",
"Access-Control-Allow-Methods": "OPTIONS,POST,GET,PUT,DELETE",
"Access-Control-Allow-Origin": "*",
"Access-Control-Max-Age": "86400"
}
isBase64Encoded (optional) - true
or false
to enable or disable base64 encoding. Default value is false
.
The output of this function is an object in a valid Lambda function proxy integration format, described here. For example, a valud output for httpResponse('hello world')
would be the following object:
{
"isBase64Encoded": false,
"statusCode": 200,
"body": "hello world",
"headers": {
"Access-Control-Allow-Headers": "Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token",
"Access-Control-Allow-Methods": "OPTIONS,POST,GET,PUT,DELETE",
"Access-Control-Allow-Origin": "*",
"Access-Control-Max-Age": "86400"
}
}
A common usage would be inside an AWS Lambda function, similar to this:
'use strict'
const httpResponse = require('api-gateway-http-response')
const parseApiEvent = require('./parse-event') // A function that parses an event
const businessLogic = require('./business-logic') // A function that handles a logic for your Lambda function
async function lambda(event) {
const request = parseApiEvent(event)
try {
const body = await businessLogic(request)
return httpResponse(body)
} catch(err) {
return httpResponse(err)
}
}
exports.handler = lambda
By default, this function will return headers that supports CORS from any origin. Supported HTTP methods are: OPTIONS, POST, GET, PUT and DELETE.
I wrote similar thing many times, packing it into a small independent package is easier that searching through other projects.
MIT -- see LICENSE
FAQs
A small library that generates API Gateway HTTP responses for Lambda proxy integration (ie. for CloudFormation and AWS SAM)
The npm package api-gateway-http-response receives a total of 3 weekly downloads. As such, api-gateway-http-response popularity was classified as not popular.
We found that api-gateway-http-response demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.