Flow Example
In this configuration:
- API requests to
api.website.com/*
are throttled with a maximum of 100 requests per minute. - If the quota is exceeded, the flow returns a 429 HTTP status code along with the message: "Quota Exceeded. Please try again later."
Flow Configuration
/etc/lunar-proxy/flows/flow.yaml
name: ClientSideLimitingFlow
filter:
url: api.website.com/*
processors:
Limiter:
processor: Limiter
parameters:
- key: quota_id
value: MyQuota
GenerateResponseLimitExceeded:
processor: GenerateResponse
parameters:
- key: status
value: 429
- key: body
value: "Quota Exceeded. Please try again later."
- key: Content-Type
value: text/plain
flow:
request:
- from:
stream:
name: globalStream
at: start
to:
processor:
name: Limiter
- from:
processor:
name: Limiter
condition: above_limit
to:
processor:
name: GenerateResponseLimitExceeded
- from:
processor:
name: Limiter
condition: below_limit
to:
stream:
name: globalStream
at: end
response:
- from:
processor:
name: GenerateResponseLimitExceeded
to:
stream:
name: globalStream
at: end
Flow Parameters (flow.yaml
)
Parameter | Example Value | Description |
---|---|---|
name | ClientSideLimitingFlow | The name of the flow, used to identify the flow in configurations. |
filter.url | api.website.com/* | Specifies the URL pattern for the API endpoints to which the flow applies. |
processors.Limiter.processor | Limiter | Defines the processor responsible for applying the rate limiting logic. |
processors.Limiter.parameters.key | quota_id | Specifies the key for the quota being used. |
processors.Limiter.parameters.value | MyQuota | The ID of the quota from the resource configuration. |
processors.GenerateResponseLimitExceeded.processor | GenerateResponse | Defines the processor that generates the response when a request exceeds the quota. |
processors.GenerateResponseLimitExceeded.parameters.key | status , body , Content-Type | Keys that define the response status code, message body, and content type when the quota is exceeded. |
/etc/lunar-proxy/quota/quota.yaml
quota:
- id: MyQuota
filter:
url: api.website.com/*
strategy:
fixed_window:
max: 100
interval: 1
interval_unit: minute
Quota Parameters
Parameter | Example Value | Description |
---|---|---|
quota_id | MyQuota | The identifier for the specific quota being applied to the flow. |
filter.url | api.website.com/* | Filters API requests by URL for applying the quota. |
strategy.fixed_window.max | 100 | The maximum number of allowed requests within a defined time window. |
strategy.fixed_window.interval | 1 | The size of the time window in which requests are counted. |
strategy.fixed_window.interval_unit | minute | Defines the unit of time for the quota window (e.g., seconds, minutes, hours). |