Whether you're a developer using a command-line interface or prefer a more visual approach through the Control Plane, this guide offers step-by-step instructions to track, monitor, manage, and optimize your API consumption and traffic.
In this section, you will learn how to install the necessary components, route API traffic, monitor and diagnose consumption, and manage API performance with Lunar.dev Flows.
Below, you'll find a helpful detailed setup instructions for Docker or Kubernetes. Let's dive in.
docker run -d --rm -p 8000:8000 -p 8081:8081 -p 8040:8040 -e TENANT_NAME="ORGANIZATION" -v $(pwd):/etc/lunar-proxy --name lunar-proxy lunarapi/lunar-proxy:latest:::caution
Note that the TENANT_NAME environment variable is required. This variable should be set to the name of your organization.
:::
curl http://localhost:8040/healthcheckA correct result should be proxy is up.
curl http://localhost:8000/fact -H "x-lunar-host: catfact.ninja" -H "x-lunar-scheme: https"Then, use the Discover command to validate that the requests were passed through Lunar Proxy.
docker exec lunar-proxy discoverhelm repo add lunar https://thelunarcompany.github.io/proxy-helm-chart/
helm repo updatehelm install lunar-proxy lunar/lunar-proxy --set tenantName=<name> --namespace lunar-proxy --create-namespaceBefore installing Lunar's Proxy, ensure that the tenantName is set to the name of your organization, for example: Acme or Google.
helm test lunar-proxycurl http://localhost:8000/fact -H "x-lunar-host: catfact.ninja" -H "x-lunar-scheme: https"Then, use the discover command to validate that the requests were passed through Lunar Proxy.
kubectl exec <lunar-proxy-pod-name> -- discoverAfter confirming successful installation of lunar.dev, enhance your API consumption with a Lunar Flow.Think of it as a customizable tool that simplifies problem-solving and smoothens API interactions by establishing rules for different scenarios.
/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: block
to:
processor:
name: GenerateResponseLimitExceeded
- from:
processor:
name: Limiter
condition: allow
to:
stream:
name: globalStream
at: end
response:
- from:
processor:
name: GenerateResponseLimitExceeded
to:
stream:
name: globalStream
at: end
- from:
stream:
name: globalStream
at: start
to:
processor:
name: end/etc/lunar-proxy/quotas/quota.yaml
quotas:
- id: MyQuota
filter:
url: api.website.com/*
strategy:
fixed_window:
max: 100
interval: 1
interval_unit: minuteIn the above example, the plugin will enforce a limit of 100 requests per minute the api.website.com/* API endpoint. If the limit is exceeded, the plugin will return a Lunar-generated API response with 429 HTTP status code.
After you have altered flow.yaml and quota.yaml according to your needs, run the load_flows command:
docker exec lunar-proxy load_flows
Check out Lunar.dev's Control Plane to see your API requests, generate and enable flows, and try the new installation-free Lunar.dev Hosted Gateway.
For any questions, feel free to reach out to us at [email protected].
kubectl exec -- discover
# Configuration
### Configure the `flow.yaml` and `quota.yaml` files
After confirming successful installation of lunar.dev, enhance your API consumption with a Lunar Flow.Think of it as a customizable tool that simplifies problem-solving and smoothens API interactions by establishing rules for different scenarios.
**/etc/lunar-proxy/flows/flow.yaml**
```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: block
to:
processor:
name: GenerateResponseLimitExceeded
- from:
processor:
name: Limiter
condition: allow
to:
stream:
name: globalStream
at: end
response:
- from:
processor:
name: GenerateResponseLimitExceeded
to:
stream:
name: globalStream
at: end
- from:
stream:
name: globalStream
at: start
to:
processor:
name: end
/etc/lunar-proxy/quotas/quota.yaml
quotas:
- id: MyQuota
filter:
url: api.website.com/*
strategy:
fixed_window:
max: 100
interval: 1
interval_unit: minuteIn the above example, the plugin will enforce a limit of 100 requests per minute the api.website.com/* API endpoint. If the limit is exceeded, the plugin will return a Lunar-generated API response with 429 HTTP status code.
After you have altered flow.yaml and quota.yaml according to your needs, run the load_flows command:
docker exec lunar-proxy load_flows
Check out Lunar.dev's Control Plane to see your API requests, generate and enable flows, and try the new installation-free Lunar.dev Hosted Gateway.
For any questions, feel free to reach out to us at [email protected].
To run tests:
cd proxy/integration-tests
cd proxy/integration-tests
pipenv install --dev
pipenv run behave

