# HttpRouteSpecOptions

Properties specific for HTTP Based Routes.

Extends: [RouteSpecOptionsBase](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appmesh.RouteSpecOptionsBase.html)
Used as argument in: [RouteSpec.http](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appmesh.RouteSpec.html#http), [RouteSpec.http2](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appmesh.RouteSpec.html#http2)

- Source: [`aws-appmesh/lib/route-spec.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-appmesh/lib/route-spec.ts#L154)

## Example

TypeScript:

```ts
declare const router: appmesh.VirtualRouter;
declare const node: appmesh.VirtualNode;

router.addRoute('route-http2-retry', {
  routeSpec: appmesh.RouteSpec.http2({
    weightedTargets: [{ virtualNode: node }],
    retryPolicy: {
      // Retry if the connection failed
      tcpRetryEvents: [appmesh.TcpRetryEvent.CONNECTION_ERROR],
      // Retry if HTTP responds with a gateway error (502, 503, 504)
      httpRetryEvents: [appmesh.HttpRetryEvent.GATEWAY_ERROR],
      // Retry five times
      retryAttempts: 5,
      // Use a 1 second timeout per retry
      retryTimeout: Duration.seconds(1),
    },
  }),
});
```

Python:

```python
# router: appmesh.VirtualRouter
# node: appmesh.VirtualNode

router.add_route("route-http2-retry",
    route_spec=appmesh.RouteSpec.http2(
        weighted_targets=[appmesh.WeightedTarget(virtual_node=node)],
        retry_policy=appmesh.HttpRetryPolicy(
            # Retry if the connection failed
            tcp_retry_events=[appmesh.TcpRetryEvent.CONNECTION_ERROR],
            # Retry if HTTP responds with a gateway error (502, 503, 504)
            http_retry_events=[appmesh.HttpRetryEvent.GATEWAY_ERROR],
            # Retry five times
            retry_attempts=5,
            # Use a 1 second timeout per retry
            retry_timeout=Duration.seconds(1)
        )
    )
)
```

Java:

```java
VirtualRouter router;
VirtualNode node;

router.addRoute("route-http2-retry", RouteBaseProps.builder()
        .routeSpec(RouteSpec.http2(HttpRouteSpecOptions.builder()
                .weightedTargets(List.of(WeightedTarget.builder().virtualNode(node).build()))
                .retryPolicy(HttpRetryPolicy.builder()
                        // Retry if the connection failed
                        .tcpRetryEvents(List.of(TcpRetryEvent.CONNECTION_ERROR))
                        // Retry if HTTP responds with a gateway error (502, 503, 504)
                        .httpRetryEvents(List.of(HttpRetryEvent.GATEWAY_ERROR))
                        // Retry five times
                        .retryAttempts(5)
                        // Use a 1 second timeout per retry
                        .retryTimeout(Duration.seconds(1))
                        .build())
                .build()))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
VirtualRouter router;
VirtualNode node;

router.AddRoute("route-http2-retry", new RouteBaseProps {
    RouteSpec = RouteSpec.Http2(new HttpRouteSpecOptions {
        WeightedTargets = new [] { new WeightedTarget { VirtualNode = node } },
        RetryPolicy = new HttpRetryPolicy {
            // Retry if the connection failed
            TcpRetryEvents = new [] { TcpRetryEvent.CONNECTION_ERROR },
            // Retry if HTTP responds with a gateway error (502, 503, 504)
            HttpRetryEvents = new [] { HttpRetryEvent.GATEWAY_ERROR },
            // Retry five times
            RetryAttempts = 5,
            // Use a 1 second timeout per retry
            RetryTimeout = Duration.Seconds(1)
        }
    })
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var router VirtualRouter
var node VirtualNode

router.addRoute(jsii.String("route-http2-retry"), &RouteBaseProps{
	RouteSpec: appmesh.RouteSpec_Http2(&HttpRouteSpecOptions{
		WeightedTargets: []WeightedTarget{
			&WeightedTarget{
				VirtualNode: node,
			},
		},
		RetryPolicy: &HttpRetryPolicy{
			// Retry if the connection failed
			TcpRetryEvents: []cONNECTION_ERROR{
				appmesh.TcpRetryEvent_*cONNECTION_ERROR,
			},
			// Retry if HTTP responds with a gateway error (502, 503, 504)
			HttpRetryEvents: []HttpRetryEvent{
				appmesh.HttpRetryEvent_GATEWAY_ERROR,
			},
			// Retry five times
			RetryAttempts: jsii.Number(5),
			// Use a 1 second timeout per retry
			RetryTimeout: awscdk.Duration_Seconds(jsii.Number(1)),
		},
	}),
})
```

## Properties

- `match`: [HttpRouteMatch](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appmesh.HttpRouteMatch.html) — The criterion for determining a request match for this Route.

  **Default:** matches on '/'

- `priority`: number — The priority for the route.

  **Default:** no particular priority

  When a Virtual Router has multiple routes, route match is performed in the
  order of specified value, where 0 is the highest priority, and first matched route is selected.

- `retryPolicy`: [HttpRetryPolicy](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appmesh.HttpRetryPolicy.html) — The retry policy.

  **Default:** no retry policy

- `timeout`: [HttpTimeout](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appmesh.HttpTimeout.html) = None — An object that represents a http timeout.

- `weightedTargets`: [WeightedTarget](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appmesh.WeightedTarget.html)[] (required) — List of targets that traffic is routed to when a request matches the route.
