ts-lambda-router
TypeScript icon, indicating that this package has built-in type declarations

0.14.5 • Public • Published

TS Lambda Router.

Router for AWS Lambdas/API Gateway proxy integration

Uses Typescript template types to provider strongly typed goodness for your API Handlers

Installation

yarn add ts-lambda-router

Demo

Demo

Usage:

import { Type } from "@sinclair/typebox";

export const Account = Type.Object({
  username: Type.String(),
  password: Type.String(),
  firstname: Type.String(),
  lastname: Type.String(),
  birthYear: Type.Integer(),
});

export const handler: APIGatewayProxyHandler =
    LambdaRouter.build((routes) =>
        routes
          .get("/accounts/{username:string}")((r) =>
            Domain
              .getAccount(r.pathParams.username)
              .then((a) => ({
                statusCode: a ? 200 : 404,
                body: JSON.stringify(a),
              })
            )
          )
          .post("/accounts", Account)(r =>
            Domain
              .saveAccount(r.body)
              .then(() => ({
                statusCode: 201,
                body: "",
              })
            )
        )

See full example at ./src/example

Readme

Keywords

none

Package Sidebar

Install

npm i ts-lambda-router

Weekly Downloads

558

Version

0.14.5

License

MIT

Unpacked Size

70.2 kB

Total Files

45

Last publish

Collaborators

  • mtranter