How to use API keys
Declare the key in use.secrets and supply its value through your Lemline secrets configuration.
Prepare the examples
Complete the SQLite setup. The examples call the partner route of the tutorial shop, GET /partner/stock. It answers HTTP 401 without credentials and HTTP 403 with a wrong value, and lists every request it received, with its headers and query, under Requests on the shop page. Start it from the root of the Lemline source checkout:
Run the other commands from the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline. The worker reads secrets from its environment when it starts, so each example below stops the worker with Ctrl+C, exports the value, and starts the worker again in the same terminal. Run the definition and instance commands from a second terminal.
Export the shop's demo values, demo-api-key as apiKey and demo-token as apiToken, and start the worker:
Send a key in a header
Set the header required by your service in with.headers. The expression resolves the secret when the task runs.
Save it as http-request-with-api-key.yaml:
Expect {"sku":"SKU-1","available":100,"authenticatedWith":"api-key-header"}. The shop lists the x-api-key header it received.
Send a key in a query parameter
Use with.query if the service requires a query parameter. Headers are preferable where the service supports them because URLs often appear in access logs.
Save it as http-request-with-query-key.yaml:
Expect {"sku":"SKU-1","available":100,"authenticatedWith":"api-key-query"}. The shop lists the request with api_key=demo-api-key in its query: the key also appears in the worker log line of the request URL.
Send a bearer token
For an API that expects Authorization: Bearer ..., use a named bearer authentication policy and reference it from with.endpoint.authentication.use.
Save it as bearer-authentication.yaml:
Expect {"sku":"SKU-1","available":100,"authenticatedWith":"bearer"}. The shop lists the authorization header Bearer demo-token.
A missing or wrong value is the service's answer, not Lemline's. Stop the worker, export a wrong key, start the worker again and repeat the first example:
The shop answers HTTP 403 and the instance faults with a communication error, status 403, titled HTTP 403: {"error":"Invalid credentials for api-key-header". Stop the shop when you are done:
See the Authentication Reference for policy placement and secret reuse.