Skip to content
Documentation
@notation/aws
Router

router

router(Api) => Router

Creates a router that can be used to define API Gateway routes.

Router

Router.get(Path, LambdaHandler) => void
Router.post(Path, LambdaHandler) => void
Router.put(Path, LambdaHandler) => void
Router.patch(Path, LambdaHandler) => void
Router.delete(Path, LambdaHandler) => void

A set of HTTP methods that create corresponding API Gateway routes.

The API Gateway routes invoke the provided lambda handler, which must be configured to handle an API Gateway event.

Parameters

type Path = `/${string}`;
type LambdaHandler = ApiGatewayHandler;

Example

infra/api.ts
import { api, router } from "@notation/aws/api-gateway";
import { greet, setGreeting } from "runtime/greeting.fn";
 
const myApi = api({ name: "myApiName" });
const myApiRouter = router(myApi);
 
myApiRouter.get("/greeting", greet);
myApiRouter.post("/greeting", setGreeting);