@lambda-middleware/json-serializer

A middleware for AWS http lambda functions to serialize JSON responses.

Usage no npm install needed!

<script type="module">
  import lambdaMiddlewareJsonSerializer from 'https://cdn.skypack.dev/@lambda-middleware/json-serializer';
</script>

README

@lambda-middleware/json-serializer

npm version downloads open issues debug build status codecov dependency status devDependency status

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);