# HttpApi

Create a new API Gateway HTTP API endpoint.

Extends: Construct › Resource › HttpApi
Implements: IResource, IApi, IHttpApi, IHttpApiRef, IEnvironmentAware, IApiRef, IConstruct, IDependable

- CloudFormation: [`AWS::ApiGatewayV2::Api`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-apigatewayv2-api.html)
- L1 type: [`CfnApi`](/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.CfnApi.html)
- Source: [`aws-apigatewayv2/lib/http/api.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-apigatewayv2/lib/http/api.ts#L385)
- Type last changed: v2.235.0 · 15 Jan 2026

## Example

```ts
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';

declare const booksDefaultFn: lambda.Function;
const booksIntegration = new HttpLambdaIntegration('BooksIntegration', booksDefaultFn);

const httpApi = new apigwv2.HttpApi(this, 'HttpApi');

httpApi.addRoutes({
  path: '/books',
  methods: [ apigwv2.HttpMethod.GET ],
  integration: booksIntegration,
});
```

## Initializer

```ts
new HttpApi(scope: Construct, id: string, props?: HttpApiProps)
```

## Construct Props

- `apiName`: string — Name for the HTTP API resource.

  **Default:** id of the HttpApi construct.

- `corsPreflight`: [CorsPreflightOptions](/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.CorsPreflightOptions.html) — Specifies a CORS configuration for an API.

  **Default:** CORS disabled.

- `createDefaultStage`: boolean = true — Whether a default stage and deployment should be automatically created.

- `defaultAuthorizationScopes`: string[] — Default OIDC scopes attached to all routes in the gateway, unless explicitly configured on the route.

  **Default:** no default authorization scopes

  The scopes are used with a COGNITO_USER_POOLS authorizer to authorize the method invocation.

- `defaultAuthorizer`: [IHttpRouteAuthorizer](/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.IHttpRouteAuthorizer.html) — Default Authorizer applied to all routes in the gateway.

  **Default:** no default authorizer

- `defaultDomainMapping`: [DomainMappingOptions](/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.DomainMappingOptions.html) — Configure a custom domain with the API mapping resource to the HTTP API.

  **Default:** no default domain mapping configured. meaningless if `createDefaultStage` is `false`.

- `defaultIntegration`: [HttpRouteIntegration](/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.HttpRouteIntegration.html) = none — An integration that will be configured on the catch-all route ($default).

- `description`: string = none — The description of the API.

- `disableExecuteApiEndpoint`: boolean — Specifies whether clients can invoke your API using the default endpoint.

  **Default:** false execute-api endpoint enabled.

  By default, clients can invoke your API with the default
  `https://{api_id}.execute-api.{region}.amazonaws.com` endpoint. Set this to
  true if you would like clients to use your custom domain name.

- `ipAddressType`: [IpAddressType](/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.IpAddressType.html) — The IP address types that can invoke the API.

  **Default:** undefined - AWS default is IPV4

- `routeSelectionExpression`: boolean = false — Whether to set the default route selection expression for the API.

  When enabled, "${request.method} ${request.path}" is set as the default route selection expression.

## Properties

- `apiEndpoint`: string — Get the default endpoint for this API.

- `apiId`: string — The identifier of this API Gateway API.

- `apiRef`: [ApiReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_apigatewayv2.ApiReference.html) — A reference to a Api resource.

- `defaultAuthorizationScopes`: string[] — Default OIDC scopes attached to all routes in the gateway, unless explicitly configured on the route.

  The scopes are used with a COGNITO_USER_POOLS authorizer to authorize the method invocation.

- `defaultAuthorizer`: [IHttpRouteAuthorizer](/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.IHttpRouteAuthorizer.html) — Default Authorizer applied to all routes in the gateway.

- `defaultStage`: [IHttpStage](/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2.IHttpStage.html) — The default stage of this API.

- `disableExecuteApiEndpoint`: boolean — Specifies whether clients can invoke this HTTP API by using the default execute-api endpoint.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `httpApiId`: string — The identifier of the HTTP API.

- `httpApiName`: string — A human friendly name for this HTTP API.

  Note that this is different from `httpApiId`.

- `isHttpApi`: boolean — Indicates that this is an HTTP API.

  Will always return true, but is necessary to prevent accidental structural
  equality in TypeScript.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

- `url`: string — Get the URL to the default stage of this API.

  Returns `undefined` if `createDefaultStage` is unset.

## Methods

- `addRoutes(options: AddRoutesOptions): HttpRoute[]` — Add multiple routes that uses the same configuration.

  The routes all go to the same path, but for different
  methods.

- `addStage(id: string, options: HttpStageOptions): HttpStage` — Add a new stage.

- `addVpcLink(options: VpcLinkProps): VpcLink` — Add a new VpcLink.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `arnForExecuteApi(method?: string, path?: string, stage?: string): string` — Get the "execute-api" ARN.

  When 'ANY' is passed to the method, an ARN with the method set to '*' is obtained.

- `fromHttpApiAttributes(scope: Construct, id: string, attrs: HttpApiAttributes): IHttpApi` (static) — Import an existing HTTP API into this CDK app.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `metric(metricName: string, props?: MetricOptions): Metric` — Return the given named metric for this Api Gateway.

- `metricClientError(props?: MetricOptions): Metric` — Metric for the number of client-side errors captured in a given period.

- `metricCount(props?: MetricOptions): Metric` — Metric for the total number API requests in a given period.

- `metricDataProcessed(props?: MetricOptions): Metric` — Metric for the amount of data processed in bytes.

- `metricIntegrationLatency(props?: MetricOptions): Metric` — Metric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend.

- `metricLatency(props?: MetricOptions): Metric` — The time between when API Gateway receives a request from a client and when it returns a response to the client.

  The latency includes the integration latency and other API Gateway overhead.

- `metricServerError(props?: MetricOptions): Metric` — Metric for the number of server-side errors captured in a given period.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
