Set-style API
Use the set-style API to configure your rate limiting rules.
This feature is an Enterprise-only feature that requires a Gloo Gateway Enterprise license.
Before you begin
Follow the Get started guide to install Gloo Gateway, set up a gateway resource, and deploy the httpbin sample app.
Get the external address of the gateway and save it in an environment variable.
Request headers
You can rate limit requests based on certain request headers.
Create a RateLimitConfig to define your rate limiting rules. In the following example, you create a policy that rate limits requests to one request per minute for requests with an
x-type
header.Create a RouteOption resource that references the RateLimitConfig that you created.
Create an HTTPRoute resource for the httpbin app that applies the RouteOption resources that you created and rate limits requests on the
ratelimit.example
domain.Send a few requests to the httpbin app on the
ratelimit.example
domain. Verify that your first request succeeds and you get back a 200 HTTP response code. Because you limited requests to one request per minute, subsequent requests within the same minute fail with a 429 HTTP response code.Example output for a successful response:
Example output when rate limited:
Change the RatelimitConfig resource to rate limit requests based on a specific header value. In the following example, the rate limiting rule is applied to the
x-type: exact-value
request header.Send a few requests to the httpbin app on the
ratelimit.example
domain and include thex-type: mytype
request header. Verify that your requests succeed and no rate limiting rules are appliedExample output for a successful response:
Send a few more requests to the httpbin app. This time, include the
x-type: exact-value
request header. Verify that the first request succeeds, but subsequent requests are rate limited.Example output for a successful response:
Example output when rate limited:
Optional: Remove the resources that you created in this guide.