# AppSyncHttpDataSource

An AppSync datasource backed by a http endpoint.

Extends: [Construct](/cdk/api/v2/docs/constructs.Construct.html) › [AppSyncBaseDataSource](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.AppSyncBaseDataSource.html) › [AppSyncBackedDataSource](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.AppSyncBackedDataSource.html) › AppSyncHttpDataSource
Implements: [IGrantable](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IGrantable.html), [IConstruct](/cdk/api/v2/docs/constructs.IConstruct.html), [IDependable](/cdk/api/v2/docs/constructs.IDependable.html)

- Source: [`aws-appsync/lib/data-source-common.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-appsync/lib/data-source-common.ts#L342)
- Type last changed: v2.193.0 · 30 Apr 2025

## Example

TypeScript:

```ts
import * as apigw from 'aws-cdk-lib/aws-apigateway';

const api = new appsync.EventApi(this, 'EventApiHttp', {
  apiName: 'HttpEventApi',
});

const randomApi = new apigw.RestApi(this, 'RandomApi');
const randomRoute = randomApi.root.addResource('random');
randomRoute.addMethod('GET', new apigw.MockIntegration({
  integrationResponses: [{
    statusCode: '200',
    responseTemplates: {
      'application/json': 'my-random-value',
    },
  }],
  passthroughBehavior: apigw.PassthroughBehavior.NEVER,
  requestTemplates: {
    'application/json': '{ "statusCode": 200 }',
  },
}), {
  methodResponses: [{ statusCode: '200' }],
});

const dataSource = api.addHttpDataSource('httpsource', `https://${randomApi.restApiId}.execute-api.${this.region}.amazonaws.com`);
```

Python:

```python
import aws_cdk.aws_apigateway as apigw

api = appsync.EventApi(self, "EventApiHttp",
    api_name="HttpEventApi"
)

random_api = apigw.RestApi(self, "RandomApi")
random_route = random_api.root.add_resource("random")
random_route.add_method("GET", apigw.MockIntegration(
    integration_responses=[apigw.IntegrationResponse(
        status_code="200",
        response_templates={
            "application/json": "my-random-value"
        }
    )],
    passthrough_behavior=apigw.PassthroughBehavior.NEVER,
    request_templates={
        "application/json": "{ \"statusCode\": 200 }"
    }
),
    method_responses=[apigw.MethodResponse(status_code="200")]
)

data_source = api.add_http_data_source("httpsource", f"https://{randomApi.restApiId}.execute-api.{this.region}.amazonaws.com")
```

Java:

```java
import software.amazon.awscdk.services.apigateway.*;

EventApi api = EventApi.Builder.create(this, "EventApiHttp")
        .apiName("HttpEventApi")
        .build();

RestApi randomApi = new RestApi(this, "RandomApi");
Resource randomRoute = randomApi.root.addResource("random");
randomRoute.addMethod("GET", MockIntegration.Builder.create()
        .integrationResponses(List.of(IntegrationResponse.builder()
                .statusCode("200")
                .responseTemplates(Map.of(
                        "application/json", "my-random-value"))
                .build()))
        .passthroughBehavior(PassthroughBehavior.NEVER)
        .requestTemplates(Map.of(
                "application/json", "{ \"statusCode\": 200 }"))
        .build(), MethodOptions.builder()
        .methodResponses(List.of(MethodResponse.builder().statusCode("200").build()))
        .build());

AppSyncHttpDataSource dataSource = api.addHttpDataSource("httpsource", String.format("https://%s.execute-api.%s.amazonaws.com", randomApi.getRestApiId(), this.region));
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.APIGateway;

var api = new EventApi(this, "EventApiHttp", new EventApiProps {
    ApiName = "HttpEventApi"
});

var randomApi = new RestApi(this, "RandomApi");
var randomRoute = randomApi.Root.AddResource("random");
randomRoute.AddMethod("GET", new MockIntegration(new IntegrationOptions {
    IntegrationResponses = new [] { new IntegrationResponse {
        StatusCode = "200",
        ResponseTemplates = new Dictionary<string, string> {
            { "application/json", "my-random-value" }
        }
    } },
    PassthroughBehavior = PassthroughBehavior.NEVER,
    RequestTemplates = new Dictionary<string, string> {
        { "application/json", "{ \"statusCode\": 200 }" }
    }
}), new MethodOptions {
    MethodResponses = new [] { new MethodResponse { StatusCode = "200" } }
});

var dataSource = api.AddHttpDataSource("httpsource", $"https://{randomApi.restApiId}.execute-api.{this.region}.amazonaws.com");
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"

api := appsync.NewEventApi(this, jsii.String("EventApiHttp"), &EventApiProps{
	ApiName: jsii.String("HttpEventApi"),
})

randomApi := apigw.NewRestApi(this, jsii.String("RandomApi"))
randomRoute := randomApi.Root.AddResource(jsii.String("random"))
randomRoute.AddMethod(jsii.String("GET"), apigw.NewMockIntegration(&IntegrationOptions{
	IntegrationResponses: []IntegrationResponse{
		&IntegrationResponse{
			StatusCode: jsii.String("200"),
			ResponseTemplates: map[string]*string{
				"application/json": jsii.String("my-random-value"),
			},
		},
	},
	PassthroughBehavior: apigw.PassthroughBehavior_NEVER,
	RequestTemplates: map[string]*string{
		"application/json": jsii.String("{ \"statusCode\": 200 }"),
	},
}), &MethodOptions{
	MethodResponses: []MethodResponse{
		&MethodResponse{
			StatusCode: jsii.String("200"),
		},
	},
})

dataSource := api.AddHttpDataSource(jsii.String("httpsource"), fmt.Sprintf("https://%v.execute-api.%v.amazonaws.com", randomApi.RestApiId, this.Region))
```

## Initializer

TypeScript:

```ts
new AppSyncHttpDataSource(scope: Construct, id: string, props: AppSyncHttpDataSourceProps)
```

Python:

```python
AppSyncHttpDataSource(scope: Construct, id: str, props: AppSyncHttpDataSourceProps)
```

Java:

```java
new AppSyncHttpDataSource(Construct scope, String id, AppSyncHttpDataSourceProps props)
```

C# / .NET:

```csharp
new AppSyncHttpDataSource(Construct scope, string id, AppSyncHttpDataSourceProps props)
```

Golang:

```go
NewAppSyncHttpDataSource(Scope Construct, Id *string, Props AppSyncHttpDataSourceProps)
```

## Construct Props

- `api`: [IApiRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_appsync.IApiRef.html) (required) — The API to attach this data source to.

- `authorizationConfig`: [AppSyncAwsIamConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.AppSyncAwsIamConfig.html) = none — The authorization config in case the HTTP endpoint requires authorization.

- `description`: string = None — The description of the data source.

- `endpoint`: string (required) — The http endpoint.

- `name`: string — The name of the data source.

  **Default:** id of data source

  The only allowed pattern is: {[_A-Za-z][_0-9A-Za-z]*}.
  Any invalid characters will be automatically removed.

- `serviceRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM service role to be assumed by AppSync to interact with the data source.

  **Default:** Create a new role

## Properties

- `grantPrincipal`: [IPrincipal](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IPrincipal.html) — The principal of the data source to be IGrantable.

- `name`: string — The name of the data source.

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

- `resource`: [CfnDataSource](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.html) — The underlying CFN data source resource.

## Methods

- `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`.

- `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.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
