http worker turns your functions into REST routes exposed as HTTP endpoints.
Before adding the worker
compose::add is served by a running Compose daemon. Keep the engine and a daemon for this project
running in separate terminals before using any of the commands below. If this project does not have
a Compose file yet, create worker-compose.yaml containing containers: {} first.
iii compose without a subcommand starts the Compose daemon. --namespace selects its namespace,
and --engine connects it to the existing engine. These options are listed in the generated
CLI reference.
Run the remaining commands from a third terminal in that same project directory:
The http worker’s server settings (port, host, CORS, timeouts) are managed at runtime through the
configuration worker.
Create endpoints
An observer ofhttp::on-request with method and path args is a route. The http worker adds the
route when the observer is added, and the target’s return value is the response.
- In a worker, register the function you want to expose, then observe
http::on-requestwith its route. If you do not have a worker yet, follow Create a new worker, then edit its source:
- Node / TypeScript
- Python
- Rust
- Go
- Add the worker to Compose, pointing at its directory:
args:
The target receives the request as
{ method, path, path_params, query_params, headers, body }, and
returns { status_code, headers, body }. A second observer of the same method and path shape is
rejected with HTTP_ROUTE_CONFLICT; await observer.ready() reports it. Disposing the observer
removes the route.
Observer filters select requests by anything in them. A request on the route that the filters
reject gets a 422 response, and the target does not run.
For streaming responses and the other configuration options, see the
http worker docs.
Calling the endpoint
Once the observer is active, setHTTP_WORKER_URL to the address configured for the http worker and
call the endpoint: