Quick Start with Terminal
Lunar.dev API Consumption Gateway Installation
- Docker
- K8S
Step 1: Install Lunar's Gateway Container
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.
Step 2: Run Post-Installation Health-Check
curl http://localhost:8040/healthcheck
A correct result should be proxy is up.
Step 3: Pass an API Request
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.dev Gateway.
docker exec lunar-proxy discover
Route your API Traffic
Lunar.dev Gateway allows you to route your HTTP requests through the Lunar.dev Gateway without needing any additional installation.
To route your requests through Lunar.dev Gateway, you need to add these headers:
- x-lunar-scheme: The original scheme of your request, e.g.,- httpsfor HTTPS requests.
- x-lunar-host: The target host, like- catfact.ninja.
- x-lunar-consumer-tag: A unique tag for your app or service. This will be removed before reaching third-party providers.
Change the request URL to route through the Lunar.dev Gateway. Use this format:
http://lunar_proxy_address:lunar_proxy_port/original/request/path
For example, if your Lunar.dev Gateway is at localhost and port 8000, the updated URL for catfact.ninja would look like this:
curl http://localhost:8000/fact -H "x-lunar-host: catfact.ninja" -H "x-lunar-scheme: https"
After adding the headers and adjusting the URL, send the request. Lunar.dev Gateway will route it efficiently while keeping the original scheme and host intact.
Configuration
Configure the flow.yaml and quota.yaml files
After confirming successful installation of lunar.dev, enhance your API consumption with a Lunar.dev Flow.Think of it as a customizable tool that simplifies problem-solving and smoothens API interactions by establishing rules for different scenarios.
In this example, we'll apply the Client side Limiting Flow. Edit the following flow.yaml and quota.yaml files
/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
/etc/lunar-proxy/quotas/quota.yaml
quotas:
  - id: MyQuota
    filter:
      url: api.website.com/*
    strategy:
      fixed_window:
        static:
          max: 100
          interval: 1
          interval_unit: minute
In 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.
Step 1: Install Lunar.dev Proxy with Helm
To install Lunar.dev Proxy using Kubernetes and Helm:
Add and Update Lunar.dev Repository
helm repo add lunar https://thelunarcompany.github.io/proxy-helm-chart/
helm repo update
Install Lunar.dev Proxy Helm Chart
To install the Helm chart:
helm install lunar-proxy lunar/lunar-proxy --set tenantName=<name> --namespace lunar-proxy --create-namespace
Make sure to replace <name> with your organization name.
Note: tenantName is mandatory. Lunar.dev Proxy will not start if it is left unset.
Verify Installation
To verify the installation, run:
helm test lunar-proxy
Alternatively, you can pass a request through the proxy:
curl http://localhost:8000/fact -H "x-lunar-host: catfact.ninja" -H "x-lunar-scheme: https"
Step 2: Discover Command
To validate that the requests were passed through the Lunar.dev Proxy, run the following command:
kubectl exec <lunar-proxy-pod-name> -- discover
Route your API Traffic in Kubernetes
To route your API traffic through Lunar.dev Gateway in Kubernetes, add the required headers (e.g., x-lunar-host, x-lunar-scheme) and use the same steps as in the Docker section.
Flow Configuration (flow.yaml)
The flow.yaml defines how API requests are processed through the Lunar.dev Proxy:
name: ClientSideLimitingFlow
filter:
  url: 18.547.41.12/*
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
Quota Configuration (quota.yaml)
The quota.yaml sets limits on API requests for specific URLs:
quotas:
  - id: MyQuota
    filter:
      url: 18.547.41.12/*
    strategy:
      fixed_window:
        static:
          max: 100
          interval: 1
          interval_unit: minute
In this configuration, API requests to 18.547.41.12/* 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."