local-dev mode runs the gateway on your machine with routes and policies from a TOML file. This example puts it in front of traefik/whoami, an HTTP echo service that returns request headers. No application code is needed.
A valid API key reaches the echo service with an X-Unkey-Principal header. Frontline rejects missing or invalid keys before they reach the service.
Prerequisites
You need Docker Compose, a keyspace, a root key with permission to verify keys in that keyspace, and an API key from that keyspace.Configure the containers
Create these three files in the same directory. Replace the root key and keyspace ID in.env with your development values.
https://api.unkey.com to verify keys by default.
The authentication policy deducts one credit from keys with limited usage for each successful request. Keys with unlimited usage are unaffected.
Start the gateway
Run these commands from the directory containing the three files:Inspect the forwarded headers
Set your API key in the terminal, then send a request through Frontline:X-Unkey-Principal, X-Forwarded-Host, and X-Forwarded-Proto: http. Header capitalization can differ. The principal’s subject is the key’s identity external ID, or its key ID if it has no identity.
Send the same request without a key to check rejection:
api service and set upstream to its Compose service name and listening port. Keep its port internal so requests cannot bypass Frontline.
Stop the example
Remove both containers and their Compose network:Next steps
The principal header
Read every field and when it is omitted.
Gateway policies
Add authentication, rate limits, and other rules to your app.