Serving Static Responses with Custom Response Policies
There are scenarios where you may want to issue static responses directly from the API Gateway rather than forwarding requests to an upstream service. This allows you to handle specific request patterns efficiently without consuming backend resources.
By defining custom response rules, you can:
đź› Return predefined error messages, such as a common 404 Not Found page.
⚡ Reduce backend load by handling certain requests at the gateway level.
🚀 Improve response times for static responses, such as maintenance messages.
🔍 What are the Benefits of Static Responses?​
Instead of routing every request to your upstream services, certain requests can be handled at the gateway layer, improving efficiency and reducing unnecessary backend calls.
Key Benefits:
- Reduce Backend Load: Offload simple responses without hitting your backend.
- Improve Performance: Serve common responses instantly at the edge.
- Standardize Error Handling: Return the same response across multiple applications.
- Enhance Availability: Provide a fallback response if your backend is unavailable.
- Handle Maintenance Windows Gracefully: Display a scheduled maintenance message without modifying backend applications.
Static Response Examples​
The following examples create an endpoint that returns a custom HTML maintenance page back for all requests to your endpoint.
Check out the custom response traffic policy action page for more details about how it functions and the parameters it accepts.
- AgentEndpoint
- CloudEndpoint
- Ingress
- Gateway API
Loading…
Loading…
đź’ˇ Ingress
resources do not natively support serving custom responses, but they can be extended using a traffic policy.
1. Create an NgrokTrafficPolicy
​
Loading…
2. Use the NgrokTrafficPolicy
on an Ingress
​
Loading…
đź’ˇ Gateway API resources do not natively support serving custom responses, but they can be extended using a traffic policy.
1. Create an NgrokTrafficPolicy
​
Loading…
2. Use the NgrokTrafficPolicy
on a Gateway
​
The following example showcases supplying the NgrokTrafficPolicy
on a Gateway
resource. All requests to the Gateway
will run the traffic policy.
If you prefer, NgrokTrafficPolicy
can also be used on the route level by using an externalRef
filter on an HTTPRoute
. See the using Gateway API guide for examples.
Loading…