ulo
ulo
Documentation

Start here

Coming from NestJSNestJS topics, mapped

The model

Protocols

HTTP Serversulo-http-hyperTLSRuntimesEmbeddingaxumactix-websalvopoemrocketWriting a server crate

Integrations

Operating

Reference

HTTP Servers

HTTP Servers

The two ways to serve an Ulo application over HTTP, a server crate that owns the sockets or a host framework that does, and how to choose between them.

ulo-http implements the routing, extraction, pre-dispatch, error rendering and the HTTP wire behaviour. It owns no socket. Something else accepts connections, and that choice is made in main.

The two shapes

Server crateEmbedding
Who owns the socketsthe appthe host framework
Cratesulo-http-hyperulo-http-axum, ulo-http-actix, ulo-http-poem, ulo-http-rocket, ulo-http-salvo
Bound withapp.bind(Server::new("0.0.0.0:8080"))app.bind(Embedded::new()), then the host mounts embedded.service()
TLS, h2c, endpoints, header timeoutsset on the serverthe host's
Routes of its own beside the appnoyes

Pick the server crate unless an existing host framework must keep its sockets, its middleware or its other routes. ulo-http-hyper is the reference: one conformance suite (ulo-http-conformance) checks every other crate in the table against the behaviour of the reference, and the differences that remain are declared by each adapter and listed on the pages below.

A server crate needs two further choices, a runtime and a listener, and both follow from one decision: tokio or smol. Runtimes covers the pairing. TLS applies to server crates only.

Starting a server

Every transport starts the same way. The server passed to bind is the line that differs between shapes (examples/01-hello):

use ulo_http_hyper::Server;
use ulo_runtime_tokio::{Tokio, shutdown_signal};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let port = std::env::var("PORT").unwrap_or_else(|_| "3000".into());
    let app = ex_01_hello::builder()
        .runtime(Tokio::current())
        .wire()?
        .connect()
        .await?
        .bind(Server::new(format!("127.0.0.1:{port}")))
        .listen()
        .await?;
    for bound in app.addresses() {
        println!("listening on http://{}", bound.addr);
    }
    app.serve(shutdown_signal()).await?;
    Ok(())
}

wire, connect, bind and listen are the application phases, and ex_01_hello is the example crate whose builder() returns the configured AppBuilder. listen prepares every server first and reports all configuration failures together, before any port is bound. A bad address, an unreadable certificate or a zero limit is a StartupError::Configure, never a port conflict.

Pages

  • ulo-http-hyper: the reference server, its settings and limits.
  • TLS: PEM files, a custom rustls configuration, ALPN.
  • Runtimes: tokio and smol, and what changes between them.
  • Embedding: how an embedding works, and what each host declares it cannot do.
  • axum, actix-web, salvo, poem, rocket: one page per host.
  • Writing a server crate: the Backend and Listener traits.

Handlers, extractors and enhancers do not depend on the choice: see Request lifecycle and Extractors.

Multipart

Read file uploads part by part, under a server body limit and a tighter per-route one.

ulo-http-hyper

The reference HTTP server, built on hyper, with its settings, defaults and limits.

On this page

The two shapesStarting a serverPages