Skip to main content
Version: Next

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)

ParameterExample ValueDescription
nameClientSideLimitingFlowThe name of the flow, used to identify the flow in configurations.
filter.urlapi.website.com/*Specifies the URL pattern for the API endpoints to which the flow applies.
processors.Limiter.processorLimiterDefines the processor responsible for applying the rate limiting logic.
processors.Limiter.parameters.keyquota_idSpecifies the key for the quota being used.
processors.Limiter.parameters.valueMyQuotaThe ID of the quota from the resource configuration.
processors.GenerateResponseLimitExceeded.processorGenerateResponseDefines the processor that generates the response when a request exceeds the quota.
processors.GenerateResponseLimitExceeded.parameters.keystatus, body, Content-TypeKeys 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

ParameterExample ValueDescription
quota_idMyQuotaThe identifier for the specific quota being applied to the flow.
filter.urlapi.website.com/*Filters API requests by URL for applying the quota.
strategy.fixed_window.max100The maximum number of allowed requests within a defined time window.
strategy.fixed_window.interval1The size of the time window in which requests are counted.
strategy.fixed_window.interval_unitminuteDefines the unit of time for the quota window (e.g., seconds, minutes, hours).
CTRL + M