Api
Source:
src/AWS/ApiGatewayV2/Api.ts
An Amazon API Gateway v2 API — the root of an HTTP API or WebSocket API.
HTTP APIs are the modern, cheaper, faster front door for Lambda functions
(compared to REST v1). WebSocket APIs provide two-way real-time messaging
backed by Lambda route handlers. Child resources (Integration, Route,
Stage, Authorizer) reference the API by passing api in their props.
HTTP APIs
Section titled “HTTP APIs”For the common “HTTP API in front of a Lambda function” case, prefer the
high-level HttpApi helper which wires up the integration, route,
stage, and invoke permission in one call.
Minimal HTTP API
import * as ApiGatewayV2 from "alchemy/AWS/ApiGatewayV2";
const api = yield* ApiGatewayV2.Api("Api", {});HTTP API with CORS
const api = yield* ApiGatewayV2.Api("Api", { corsConfiguration: { AllowOrigins: ["https://example.com"], AllowMethods: ["GET", "POST"], AllowHeaders: ["content-type"], MaxAge: 3600, },});WebSocket APIs
Section titled “WebSocket APIs”const api = yield* ApiGatewayV2.Api("WsApi", { protocolType: "WEBSOCKET", routeSelectionExpression: "$request.body.action",});Endpoint hardening
Section titled “Endpoint hardening”const api = yield* ApiGatewayV2.Api("Api", { disableExecuteApiEndpoint: true,});