How to make an HTTP call
Set call: http and configure the HTTP method and endpoint under with.
The examples call the tutorial shop. Complete the SQLite setup and keep its worker running. Start the shop from the root of the Lemline source checkout, then run the other commands from a second terminal in the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline.
Save this definition as check-stock.yaml:
The response body becomes the task output: {"sku":"SKU-1","available":100,"reserved":0}.
Build the request
Use headers and query for request headers and query parameters. For a POST or PUT request, supply body as a value or a workflow expression. See the HTTP Task Reference for request options and output modes.
Use a dynamic endpoint
Use a jq expression for the complete endpoint when it depends on task input. Escape an input value before inserting it into the URL path.
Save it as dynamic-http-endpoint.yaml and read one known and one unknown product:
The first instance returns the watering can, {"id":"SKU-2","name":"Watering can","category":"garden","price":12,"available":10}. For the second, @uri sends /products/SKU%20404; the shop answers HTTP 404 and the workflow faults with a communication error, status 404, whose title starts with HTTP 404. Write path templates such as {productId} as an expression like this one: Lemline does not expand URI templates.
Authenticate
Use a service-specific header or query parameter for an API key. Use an endpoint authentication policy for basic or bearer authentication.
Recover from an HTTP error
Wrap the call in a try task, select the errors to handle in catch, and add a retry policy or a fallback list where appropriate. A failed HTTP call raises a communication error whose status is the HTTP status and whose title is HTTP <code>: <body>. Match it with catch.errors.with, as here.
The failures input makes the shop answer HTTP 503 that many times. Save the definition as retry-and-fallback.yaml:
The first instance returns the stock after one retry. The second fails four times, then returns {"inventory":[],"stale":true}. Allow about a minute: the worker picks up delayed retries every 10 seconds. Stop the shop when you are done:
Run the checkout workflow to see request bodies, HTTP failure handling and idempotent release against a local service.