@lambda-middleware/json-serializer
v2.1.1
Published
A middleware for AWS http lambda functions to serialize JSON responses.
Downloads
29
Maintainers
Readme
@lambda-middleware/json-serializer
A middleware for AWS http lambda functions to serialize JSON responses, including correct status codes and content-header.
Please note that this middleware just uses JSON.stringify
for serialization and therefore does not strip any serializable content.
Please act as if any data your handler returns could end up on the client side and take care of appropriate whitelisting in the handler or a different middleware!
Lambda middleware
This middleware is part of the lambda middleware series. It can be used independently.
Usage
import { jsonSerializer } from "@lambda-middleware/json-serializer";
interface Response {
// Undefined values will be stripped out
name?: string;
}
// This is your AWS handler
async function helloWorld(): Promise<Response> {
return {};
}
// Wrap the handler with the middleware
export const handler = jsonSerializer()(helloWorld);