Method
Source:
src/AWS/ApiGateway/Method.ts
An HTTP method on an API Gateway Resource.
A Method is a single HTTP verb (GET, POST, ANY, …) attached to a
REST API resource path. Most methods also carry an integration — the
downstream target that actually handles the request (a Lambda function,
an HTTP endpoint, a mock response, etc.).
Binding to a RestApi
Section titled “Binding to a RestApi”Pass the RestApi value on restApi. This threads the API id through
and registers the method as a RestApiBinding on the API, so that any
Deployment of the same API is automatically ordered after this method
completes. You do not need to manage Deployment.triggers yourself.
yield* ApiGateway.Method("GetRoot", { restApi: api, httpMethod: "GET", authorizationType: "NONE", integration: { type: "MOCK" },});Lambda proxy integration
Section titled “Lambda proxy integration”For Lambda-backed APIs, the integration uri follows the
arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/<function-arn>/invocations
shape. Use Output.map to resolve the function ARN before building the
URI, since the function’s ARN is only known at deploy time.
import * as Output from "alchemy/Output";
const invokeUri = Output.map( fn.functionArn, (arn) => `arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${arn}/invocations`,);
yield* ApiGateway.Method("RootAny", { restApi: api, httpMethod: "ANY", authorizationType: "NONE", integration: { type: "AWS_PROXY", integrationHttpMethod: "POST", uri: invokeUri, },});Methods on sub-paths
Section titled “Methods on sub-paths”Attach a method to a nested path by creating an ApiGateway.Resource and
passing its resourceId explicitly. restApi is still required so the
method binds for deployment ordering.
const items = yield* ApiGateway.Resource("Items", { restApi: api, parentId: api.rootResourceId, pathPart: "items",});
yield* ApiGateway.Method("ListItems", { restApi: api, resourceId: items.resourceId, httpMethod: "GET", authorizationType: "NONE", integration: { type: "MOCK" },});