Route Your API Traffic
Once the gateway is installed, the next step is to route your API traffic through the Lunar.dev Gateway.
You can directly route your traffic without installing additional software by simply modifying your HTTP requests with specific headers and adjusting the request URL.
HTTPS communication is available for users on Lunar.dev Pro for enhanced security.
Setupโ
- Prepare Your Request
Start with the request you wish to make, for example,ย https://catfact.ninja/fact
.
- Add Necessary Headers
Any header starting with x-lunar
will be automatically removed before the request is forwarded to third-party providers. Ensure these headers are included for internal routing and management purposes only.
Incorporate the following headers into your request:
x-lunar-scheme
: Reflects the original scheme of your request. For HTTPS requests, useยhttps
.x-lunar-host
: The host you intend to communicate with, such asยcatfact.ninja
,some.api.com
,10.415.12.15
ย for the given example.x-lunar-consumer-tag
(optional): Use this header to indicate the originating application or service, helpful for traffic segmentation.
Your request now should carry these additional headers.
- Modify the Request URL
Alter the URL of your request to route through the Lunar.dev Proxy. Use the format: http://lunar_proxy_address:lunar_proxy_port/original/request/path
Replace lunar_proxy_address
with the DNS or IP of the Lunar.dev Proxy, and lunar_proxy_port
with the listening port number.
For instance, with the Lunar.dev Proxy at localhost
and port 8000
, the modified URL for our example would be:
- Headers
- Query Parameters
curl http://localhost:8000/fact -H "x-lunar-host: catfact.ninja" -H "x-lunar-scheme: https" -H "x-lunar-consumer-tag: example-app"
Or, with wget:
wget -qO - --header="x-lunar-host: catfact.ninja" --header="x-lunar-scheme: https" --header="x-lunar-consumer-tag: example-app" http://localhost:8000/fact
To use query parameters for redirection in Direct Mode, you need to start the Lunar.dev Proxy with the environment variable LUNAR_REDIRECTION_BY_QUERY_PARAMS=1
. This enables the proxy to accept query parameters in the request.
curl http://localhost:8000/fact?lunar_original_scheme=https&lunar_original_host=catfact.ninja&lunar-consumer-tag=example-app
Or, with wget:
wget -qO - "http://localhost:8000/fact?lunar_original_scheme=https&lunar_original_host=catfact.ninja&lunar-consumer-tag=example-app"
- Execute Your Request
With the headers added and the URL adjusted, send your request. Direct Mode will ensure it's efficiently directed to the intended destination while preserving the original scheme and host.