Expose Wasm Components and messaging channels as HTTP endpoints.
The HTTP server maps incoming HTTP requests to component function invocations or to messages published to a channel based on TOML route configuration. It runs as a runtime Service, starting automatically when [server.*] definitions with type = "http" are present.
Server routes are defined under [server.<name>] in TOML config files.
Invoke a component function, mapping path parameters and an optional request body to function arguments:
[server.api]
type = "http"
port = 8080
[server.api.route.get-user]
path = "/users/{id}"
component = "user-service"
function = "get-user"
[server.api.route.create-user]
path = "/users"
component = "user-service"
function = "create"
body = "user"Publish the raw request body to a messaging channel:
[server.api.route.events]
path = "/events"
channel = "incoming-events"| Property | Required | Description |
|---|---|---|
path |
yes | URL path with optional {param} segments |
component |
yes* | Component to invoke |
function |
yes* | Function name on the component |
body |
no | Names a function parameter to populate from the request body |
channel |
yes* | Channel to publish to (mutually exclusive with component/function) |
method |
no | HTTP method (see defaults below) |
* Either component + function or channel is required, never both.
If method is not specified, it is inferred:
- Component routes with
bodydefault to POST - Component routes without
bodydefault to GET - Channel routes default to POST (the only valid option)
Component routes currently support two content types for the request body:
application/json(default): parsed as JSONtext/plain: wrapped as a JSON string value
Other content types are rejected with 415 Unsupported Media Type.
Channel routes forward the raw request body and content-type header to the channel. The activator handles content-type interpretation when the message is consumed.
All component route responses are JSON-serialized with content-type: application/json.
The config handler rejects:
- Duplicate routes (same method and path structure)
bodyparam name that collides with a path param namebodywith method GETbodyon channel routes (since it's the payload, not a named param)- GET with channel routes
composable-http-server config.toml [additional-configs...]Multiple config files are merged, allowing separation of concerns (e.g. domain components, infrastructure capabilities, server routes in separate files). The default log level is info, overridable via the RUST_LOG environment variable.
Register the HTTP service with a RuntimeBuilder:
use composable_runtime::Runtime;
use composable_http_server::HttpService;
let runtime = Runtime::builder()
.from_paths(&config_paths)
.with_service::<HttpService>()
.build()
.await?;
runtime.run().awaitThe service claims [server.*] definitions where type = "http", so other server types can coexist under the same [server.*] category using different type selectors.