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

Runtimes

The runtime and listener crates a server is built from, with tokio and smol side by side.

A server crate does not pick a runtime. The app has one, set with AppBuilder::runtime(..), and every task the server starts (each connection, HTTP/2 stream tasks, the header-read clock) goes through it. The sockets come from a listener crate that matches it.

tokiosmol
Runtime crateulo-runtime-tokioulo-runtime-smol
Runtime valueTokio::current()Smol::new(Arc::new(Executor::new()))
Listener crateulo-listener-tokioulo-listener-smol
Listener typeTokioListenerSmolListener
Sockets and TLStokio sockets, tokio-rustlsasync-net sockets, futures-rustls
hyper server typeulo_http_hyper::Serverulo_http_hyper::ServerOn::<SmolListener>
Shutdown signalshutdown_signal()written by the application

ulo-http-hyper's default tokio feature builds the tokio listener and the Server alias over it. A smol application sets default-features = false so no tokio runtime crate is built.

tokio

Every example except examples/22-http-on-smol runs here. The runtime is Tokio::current(), taken inside #[tokio::main], and shutdown_signal() resolves on SIGINT or SIGTERM.

A tokio listener adopts its sockets into tokio's reactor, so a tokio runtime must be running when the server binds. An app whose runtime is not ulo_runtime_tokio::Tokio and that binds a tokio-listener server is refused at bind, with an error naming the listener.

smol

examples/22-http-on-smol is the same controller as example 01 on smol. ulo-runtime-smol takes an async-executor Executor that the caller owns and runs, and Smol::block_on drives the app on it. No tokio runtime is in the dependency tree.

pub fn server(endpoint: &str) -> ulo_http_hyper::ServerOn<ulo_listener_smol::SmolListener> {
    ulo_http_hyper::ServerOn::new(endpoint)
}
use std::sync::Arc;

use ulo_runtime_smol::{Executor, Smol};

fn main() -> Result<(), ulo::BoxError> {
    let port = std::env::var("PORT").unwrap_or_else(|_| "3000".into());
    let smol = Smol::new(Arc::new(Executor::new()));
    smol.block_on(async {
        let app = ex_22_http_on_smol::builder()
            .runtime(smol.clone())
            .wire()?
            .connect()
            .await?
            .bind(ex_22_http_on_smol::server(&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(())
    })
}

shutdown_signal here is the function the example defines, described below.

The example's Cargo manifest turns the tokio feature off:

ulo-http-hyper = { path = "../../crates/ulo-http-hyper", default-features = false }
ulo-listener-smol = { path = "../../crates/ulo-listener-smol" }
ulo-runtime-smol = { path = "../../crates/ulo-runtime-smol" }

Only the tokio runtime crate ships a shutdown future. The smol example writes its own over async-signal, resolving on the first SIGINT or SIGTERM and returning a ulo::Signal.

The smol runtime never refuses to spawn or sleep. Its executor is the caller's: a spawned task makes progress only while some thread runs the executor.

The hyper dependency

hyper depends on tokio with its sync feature, for a channel inside its upgrade future. Tokio's synchronisation primitives are therefore in every hyper server's tree, the smol one included. Its executor, reactor and timers are not.

Other runtimes

ulo-server-hyper implements the accept loop that ulo-http-hyper, ulo-ws-hyper and the gRPC server share. A new runtime supplies a Runtime and a Listener; see Writing a server crate.

TLS

Serving HTTPS from a PEM certificate chain and key, or from a rustls configuration of your own.

Embedding

Running an Ulo application inside axum, actix-web, poem, rocket or salvo, and what each host declares it cannot do.

On this page

tokiosmolThe hyper dependencyOther runtimes