🔄 Seamless service rollouts by routing requests based on versioning, headers, or user location.
🛡 Enhanced reliability with failover and fallback mechanisms.
🔍 What are the benefits of request routing?
Modern applications often consist of multiple microservices that serve different functions. A well-configured API Gateway can intelligently route traffic based on:- Path-based rules (/api/v1/orders → Order Service, /api/v1/users → User Service).
- Header-based conditions (User-Agent: Mobile → Mobile Backend, User-Agent: Desktop → Web Backend).
- Query parameters & cookies (A/B testing, canary deployments).
- Efficiently Direct Requests: Ensure each request reaches the correct service, region, or version.
- Enable Canary & Blue-Green Deployments: Route a subset of traffic to new versions before full rollout.
- Improve Scalability: Load balance requests across multiple backend instances.
- Enhance Security & Compliance: Route traffic based on user identity, location, or authentication level.
- Optimize Multi-Region Deployments: Direct users to the nearest geographically distributed service.
Using CloudEndpoints with AgentEndpoints
AgentEndpoint resources allow you to configure an upstream that should receive the traffic sent to the AgentEndpoint, but you can only specify a single upstream.
CloudEndpoint resources do not have configuration for an upstream, but you can use Traffic Policy configuration with the forward-internal action to forward to other endpoints.
The most common pattern is to create an internal AgentEndpoint for your upstream services. An internal endpoint is used so that your upstream service is not directly accessible to the public internet, but other ngrok endpoints can route to it using the forward-internal action.
Then, a CloudEndpoint resource is created for the hostname that you would like to use. The CloudEndpoint is then given Traffic Policy configuration to forward to your AgentEndpoints.
This makes it simple to have a central resource for a given hostname that defines Traffic Policy actions for things like rate-limiting and authentication that you may like to enforce for the entire hostname while having all of the routing rules for the hostname located in the same location.
The following example showcases how you can create two different internal AgentEndpoint resources for two different upstream services, and then use a CloudEndpoint to accept traffic for an example hostname and route to the desired AgentEndpoint.
CloudEndpoint and AgentEndpoint resources offer a lot of flexibility in determining when to run Traffic Policy actions.
Check out the Traffic Policy expressions page for more information about the expressions you can write.
Exact path matching
The following examples showcase how you can match on an exact path. The request will not be routed unless it has the exact path/example, so /example/foo will not be routed.
- CloudEndpoint with AgentEndpoint
- Ingress
- Gateway API
Path prefix matching
The following examples showcase how you can match using a path prefix. Any request that has a path starting with/example will be routed, so /example/foo will be routed as well.
- CloudEndpoint with AgentEndpoint
- Ingress
- Gateway API
Request method matching
The following examples showcase how to create an endpoint that only routes requests with thePOST method.
- CloudEndpoint with AgentEndpoint
- Ingress
- Gateway API
Exact header matching
The following examples showcase how to create an endpoint that only routes requests if the headerx-request-header is present with value foo.
- CloudEndpoint with AgentEndpoint
- Ingress
- Gateway API
Regex header matching
The following examples showcase how to create an endpoint that only routes requests if the headerx-request-header is present and the value matches the regex x-value-.*
- CloudEndpoint with AgentEndpoint
- Ingress
- Gateway API
Exact query parameter matching
The following examples showcase how to create an endpoint that only routes requests if the query parametermy-query-param is present with value foo.
- CloudEndpoint with AgentEndpoint
- Ingress
- Gateway API
Regex query parameter matching
The following examples showcase how to create an endpoint that only routes requests if the query parametermy-query-param is present and its value matches the regex value-.*.