Skip to main content
The 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 of http::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.
  1. In a worker, register the function you want to expose, then observe http::on-request with its route. If you do not have a worker yet, follow Create a new worker, then edit its source:
  1. Add the worker to Compose, pointing at its directory:
The route is set by the observer’s 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, set HTTP_WORKER_URL to the address configured for the http worker and call the endpoint: