# HttpIntegration

You can integrate an API method with an HTTP endpoint using the HTTP proxy integration or the HTTP custom integration,.

With the proxy integration, the setup is simple. You only need to set the
HTTP method and the HTTP endpoint URI, according to the backend requirements,
if you are not concerned with content encoding or caching.

With the custom integration, the setup is more involved. In addition to the
proxy integration setup steps, you need to specify how the incoming request
data is mapped to the integration request and how the resulting integration
response data is mapped to the method response.

Extends: [Integration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.Integration.html) › HttpIntegration

- Source: [`aws-apigateway/lib/integrations/http.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-apigateway/lib/integrations/http.ts#L40)

## Example

TypeScript:

```ts
declare const authFn: lambda.Function;
declare const books: apigateway.Resource;

const auth = new apigateway.RequestAuthorizer(this, 'booksAuthorizer', {
  handler: authFn,
  identitySources: [apigateway.IdentitySource.header('Authorization')]
});

books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), {
  authorizer: auth
});
```

Python:

```python
# auth_fn: lambda.Function
# books: apigateway.Resource

auth = apigateway.RequestAuthorizer(self, "booksAuthorizer",
    handler=auth_fn,
    identity_sources=[apigateway.IdentitySource.header("Authorization")]
)

books.add_method("GET", apigateway.HttpIntegration("http://amazon.com"),
    authorizer=auth
)
```

Java:

```java
Function authFn;
Resource books;

RequestAuthorizer auth = RequestAuthorizer.Builder.create(this, "booksAuthorizer")
        .handler(authFn)
        .identitySources(List.of(IdentitySource.header("Authorization")))
        .build();

books.addMethod("GET", new HttpIntegration("http://amazon.com"), MethodOptions.builder()
        .authorizer(auth)
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Function authFn;
Resource books;

var auth = new RequestAuthorizer(this, "booksAuthorizer", new RequestAuthorizerProps {
    Handler = authFn,
    IdentitySources = new [] { IdentitySource.Header("Authorization") }
});

books.AddMethod("GET", new HttpIntegration("http://amazon.com"), new MethodOptions {
    Authorizer = auth
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var authFn Function
var books Resource

auth := apigateway.NewRequestAuthorizer(this, jsii.String("booksAuthorizer"), &RequestAuthorizerProps{
	Handler: authFn,
	IdentitySources: []*string{
		apigateway.IdentitySource_Header(jsii.String("Authorization")),
	},
})

books.AddMethod(jsii.String("GET"), apigateway.NewHttpIntegration(jsii.String("http://amazon.com")), &MethodOptions{
	Authorizer: auth,
})
```

## Initializer

TypeScript:

```ts
new HttpIntegration(url: string, props?: HttpIntegrationProps)
```

Python:

```python
HttpIntegration(url: str, props: typing.Optional[HttpIntegrationProps] = None)
```

Java:

```java
new HttpIntegration(String url, HttpIntegrationProps props)
```

C# / .NET:

```csharp
new HttpIntegration(string url, HttpIntegrationProps? props = null)
```

Golang:

```go
NewHttpIntegration(Url *string, Props HttpIntegrationProps)
```

## Methods

- `bind(method: Method): IntegrationConfig` — Can be overridden by subclasses to allow the integration to interact with the method being integrated, access the REST API object, method ARNs, etc.
