# WithGatewayPathRoute

- Module: [Aspire.Hosting.Kubernetes](/reference/api/go/aspire.hosting.kubernetes.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: [`KubernetesGatewayResource`](/reference/api/go/aspire.hosting.kubernetes/kubernetesgatewayresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Adds a path-based routing rule to the gateway. The rule matches each hostname configured with `WithHostname`, or all hosts when no hostname is configured, and routes matching traffic to the endpoint's backing Kubernetes service. This generates an `HTTPRoute` resource attached to the Gateway.

## Definition

```go
func (KubernetesGatewayResource) WithGatewayPathRoute(
    path string,
    endpoint EndpointReference,
    options ...*WithGatewayPathRouteOptions,
) KubernetesGatewayResource
```

## Parameters

- `path` (`string`) -- The URL path to match (e.g., `"/"` or `"/api"`). Must start with `/`.
- `endpoint` (`EndpointReference`) -- The endpoint reference identifying the target service and port.
- `options` (`...*WithGatewayPathRouteOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*WithGatewayPathRouteOptions` argument.

- `PathType` ([`*GatewayPathMatchType`](/reference/api/go/aspire.hosting.kubernetes/gatewaypathmatchtype.md)) -- The path matching strategy. Defaults to `PathPrefix`.

## Returns

[`KubernetesGatewayResource`](/reference/api/go/aspire.hosting.kubernetes/kubernetesgatewayresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- [`KubernetesGatewayResource`](/reference/api/go/aspire.hosting.kubernetes/kubernetesgatewayresource.md)
