npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@foladayo/lambda-adapter-kit

v1.0.3-1

Published

Framework-agnostic Lambda event and web request/response conversion utilities

Downloads

29

Readme

lambda-adapter-kit

Framework-agnostic AWS Lambda event and web request/response conversion utilities

npm version TypeScript

Convert between AWS Lambda events and standard Web API requests/responses for any framework.

Inspiration: This package is heavily inspired by the Hono.js AWS Lambda adapter, reimagined as a framework-agnostic utility library.

Installation

npm install @foladayo/lambda-adapter-kit
# or
pnpm add @foladayo/lambda-adapter-kit
# or
yarn add @foladayo/lambda-adapter-kit

Quick Start

Basic Event Conversion

import { convertLambdaEventToWebRequest, convertWebResponseToLambdaEvent } from "@foladayo/lambda-adapter-kit";

export const handler = async (event, context) => {
  // Convert Lambda event → Web Request
  const request = convertLambdaEventToWebRequest(event);

  // Your app logic here
  const response = new Response("Hello World", {
    status: 200,
    headers: { "Content-Type": "text/plain" },
  });

  // Convert Web Response → Lambda response
  return await convertWebResponseToLambdaEvent(response);
};

Framework Handler

import { createLambdaHandler } from "@foladayo/lambda-adapter-kit";

// Works with any framework that has a fetch method
const app = {
  fetch: async (request) => {
    return new Response(`Hello ${new URL(request.url).pathname}`);
  },
};

export const handler = createLambdaHandler(app, {
  binaryMediaTypes: ["image/*"],
});

What's Included

  • 🔄 Event Converters - Lambda ↔ Web API conversion
  • 🛠️ Handler Utilities - Framework-agnostic Lambda handlers
  • 🎯 TypeScript Ready - Full type safety
  • ⚡ Zero Dependencies - Lightweight and fast
  • 🔧 Framework Agnostic - Works with any fetch-based framework

Core Functions

convertLambdaEventToWebRequest(event)

Converts an AWS Lambda event to a standard Web API Request object.

import { convertLambdaEventToWebRequest } from "@foladayo/lambda-adapter-kit";

// Supports: API Gateway v1/v2, ALB, Lambda Function URLs
const request = convertLambdaEventToWebRequest(event);

// Now you can use standard Web API methods
const url = new URL(request.url);
const method = request.method;
const body = await request.text();
const headers = request.headers;

convertWebResponseToLambdaEvent(response, options?)

Converts a standard Web API Response object to AWS Lambda event response format.

import { convertWebResponseToLambdaEvent } from "@foladayo/lambda-adapter-kit";

const response = new Response(JSON.stringify({ message: "Hello World" }), {
  status: 200,
  headers: {
    "Content-Type": "application/json",
    "Set-Cookie": "session=abc123; HttpOnly",
  },
});

const lambdaResponse = await convertWebResponseToLambdaEvent(response, {
  binaryMediaTypes: ["image/*", "application/pdf"],
  multiValueHeaders: false, // Set to true for ALB events
});

// Returns: { statusCode: 200, headers: {...}, body: "...", isBase64Encoded: false }

createLambdaHandler(app, options?)

Create a Lambda handler for any framework that implements the fetch interface:

import { createLambdaHandler } from "@foladayo/lambda-adapter-kit";

// For any framework with a fetch method
const app = {
  fetch: async (request) => {
    // Your application logic
    return new Response("Hello World");
  },
};

// Create Lambda handler
export const handler = createLambdaHandler(app, {
  binaryMediaTypes: ["image/*"],
  multiValueHeaders: false, // Set to true for ALB events
});

Utility Functions

Additional framework-agnostic utilities:

import {
  normalizeHeaders,
  parseMultiValueHeaders,
  isValidHttpMethod,
  sanitizePath,
} from "@foladayo/lambda-adapter-kit";

// Normalize headers for consistent format
const headers = normalizeHeaders(rawHeaders);

// Parse comma-separated header values
const multiHeaders = parseMultiValueHeaders(headers);

// Validate HTTP method
if (isValidHttpMethod("POST")) {
  // Process request
}

// Clean and normalize URL paths
const cleanPath = sanitizePath("/api//users///123"); // → '/api/users/123'

Supported Lambda Events

| Event Type | Support | Notes | | ----------------------------------- | ------- | ------------------- | | API Gateway v1 | ✅ | REST API format | | API Gateway v2 | ✅ | HTTP API format | | ALB (Application Load Balancer) | ✅ | Multi-value headers | | Lambda Function URLs | ✅ | Direct invocation |

Features

  • 🔄 Automatic Binary Detection - Content-type based base64 encoding
  • 🍪 Cookie Handling - Proper Set-Cookie header support
  • 📦 Multi-Value Headers - ALB and API Gateway compatibility
  • 🗜️ Compression Support - Gzip, deflate, brotli detection
  • 🛡️ Type Safety - Complete TypeScript definitions
  • 🔧 Framework Agnostic - Works with any fetch-based framework
  • ⚡ Zero Dependencies - Lightweight and fast

TypeScript Support

All functions and types are fully typed:

import type {
  LambdaEvent, // Union of all Lambda event types
  ResponseConversionOptions, // Response conversion options
  FetchApp, // App interface for handlers
  LambdaHandlerOptions, // Handler configuration
} from "@foladayo/lambda-adapter-kit";

// LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2 | ALBEvent
function handleLambdaEvent(event: LambdaEvent) {
  return convertLambdaEventToWebRequest(event);
}

Framework Integrations

SvelteKit

For SvelteKit applications, use the dedicated adapter:

npm install @foladayo/sveltekit-adapter-lambda
// svelte.config.js
import adapter from "@foladayo/sveltekit-adapter-lambda";

export default {
  kit: {
    adapter: adapter(),
  },
};

Other Frameworks

This package can be used with any framework that supports the fetch interface:

  • Hono - Fast web framework

Examples

Hono Integration

import { Hono } from "hono";
import { createLambdaHandler } from "@foladayo/lambda-adapter-kit";

const app = new Hono();

app.get("/", (c) => c.text("Hello Hono!"));
app.post("/api/users", async (c) => {
  const user = await c.req.json();
  return c.json({ id: 1, ...user });
});

export const handler = createLambdaHandler(app);

Requirements

  • Node.js: 20+ (AWS Lambda nodejs20.x runtime)

Contributing

git clone https://github.com/oladayo21/lambda-adapter-kit
cd lambda-adapter-kit
pnpm install
pnpm test

License

MIT © Foladayo