Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Composable HTTP Server

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.


Configuration

Server routes are defined under [server.<name>] in TOML config files.

Component routes

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"

Channel routes

Publish the raw request body to a messaging channel:

[server.api.route.events]
path = "/events"
channel = "incoming-events"

Route properties

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.

Method defaults

If method is not specified, it is inferred:

  • Component routes with body default to POST
  • Component routes without body default to GET
  • Channel routes default to POST (the only valid option)

Content types

Component routes currently support two content types for the request body:

  • application/json (default): parsed as JSON
  • text/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.

Validation

The config handler rejects:

  • Duplicate routes (same method and path structure)
  • body param name that collides with a path param name
  • body with method GET
  • body on channel routes (since it's the payload, not a named param)
  • GET with channel routes

Standalone binary

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.


Library usage

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().await

The service claims [server.*] definitions where type = "http", so other server types can coexist under the same [server.*] category using different type selectors.