ts-lambda-router
v0.14.5
Published
Router for AWS Lambdas/API Gateway proxy integration
Downloads
977
Readme
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
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