ulo
ulo
Documentation

Start here

Coming from NestJSNestJS topics, mapped

The model

Protocols

Integrations

Operating

CLICLI InstallationCLI Commands

Reference

CLI

CLI Commands

ulo new, ulo generate and ulo dev, with every option and the files each writes.

ulo new

ulo new <name> [--transport <transport>] [--db <module>-<backend>]

Writes a project into a new directory named <name>. The name is letters, digits, - and _, starts with a letter, and is not a Rust keyword or the name of a crate the project depends on. The command refuses an existing directory and removes what it wrote if a write fails.

ulo new my-app
cd my-app
cargo test
cargo run
curl http://127.0.0.1:3000/greetings/Ada
# {"message":"Hello, Ada!"}

The files are described on Project Structure. The project's ulo-* dependencies are pinned to the CLI's exact version, as ulo = "=0.1.0-alpha.3", which resolves from crates.io.

Transports

--transport defaults to http.

TransportServesHealth
httpHTTP/1.1 and HTTP/2 on hyper/health/live, /health/ready, /health/started
wsA WebSocket gateway on the HTTP server's portThe same HTTP probes
grpcgRPC from proto/greeter.protogrpc.health.v1
rpc-tcp, rpc-udpRPC over TCP or UDPNone
rpc-nats, rpc-redis, rpc-rabbitmq, rpc-mqtt, rpc-kafkaRPC over a brokerNone

rpc-kafka builds librdkafka and needs a C toolchain. A broker transport connects to the broker named in config/app.toml when the project starts. Default addresses written to config/app.toml:

TransportKeyValue
http, wsserver.address127.0.0.1:3000
grpcserver.address127.0.0.1:50051
rpc-tcpserver.address127.0.0.1:7000
rpc-udpserver.address127.0.0.1:7001
rpc-natsserver.urlnats://127.0.0.1:4222
rpc-redisserver.urlredis://127.0.0.1:6379
rpc-rabbitmqserver.urlamqp://guest:guest@127.0.0.1:5672/%2f
rpc-mqttserver.urlmqtt://127.0.0.1:1883
rpc-kafkaserver.brokers127.0.0.1:9092

Environment variables named APP_<SECTION>__<KEY> override the file: APP_SERVER__ADDRESS overrides server.address.

Databases

--db adds a database layer: the store module imported in src/app.rs, a [database] section in config/app.toml, and src/database.rs, a service that injects the client.

--dbClientRust
sqlx-postgres, sqlx-mysql, sqlx-sqlitesqlx::PgPool, MySqlPool, SqlitePool1.94
seaorm-postgres, seaorm-mysql, seaorm-sqlitesea_orm::DatabaseConnection1.94
diesel-postgres, diesel-mysql, diesel-sqliteA deadpool Pool of diesel-async connections1.89
mongodbmongodb::Client1.88
redisredis::aio::ConnectionManager1.88

The generated manifest states the Rust version the combination needs. Migrations are not generated; each store module takes them through .migrate(..). See Database.

ulo generate

ulo generate <module|provider|controller|gateway|resolver> <name> [--transport <http|rpc>]

Run it from the project root. It writes one new file under src/ and prints the lines that register it. It edits no existing source, since rewriting a file loses its formatting and comments. It refuses to overwrite a file and refuses a name that is not a Rust identifier. --transport applies to controller alone.

KindFileItem
modulesrc/<name>_module.rs<Name>Module
providersrc/<name>.rs<Name>
controllersrc/<name>_controller.rs<Name>Controller; --transport rpc for RPC handlers, HTTP otherwise
gatewaysrc/<name>_gateway.rs<Name>Gateway
resolversrc/<name>_resolver.rs<Name>Resolver, an async-graphql root object
ulo generate controller user_profile
Created src/user_profile_controller.rs

Declare it where the project's modules are, usually src/main.rs:
    mod user_profile_controller;

Register it in the module that serves it:
    m.controller::<crate::user_profile_controller::UserProfileController>();

It needs these in Cargo.toml:
    ulo-http = "=0.1.0-alpha.3"

The generated controller serves GET /user-profile:

src/user_profile_controller.rs
use serde::Serialize;
use ulo::{controller, handlers};
use ulo_http::Json;

#[derive(Debug, Serialize)]
pub struct UserProfileListing {
    pub items: Vec<String>,
}

#[controller]
pub struct UserProfileController;

#[handlers]
impl UserProfileController {
    #[ulo_http::get("/user-profile")]
    fn list(&self) -> Json<UserProfileListing> {
        Json(UserProfileListing { items: Vec::new() })
    }
}

Registration lines per kind:

KindPrinted registration
modulem.import(crate::<name>_module::<Name>Module);
providerm.provide::<crate::<name>::<Name>>();
controllerm.controller::<crate::<name>_controller::<Name>Controller>();
gatewayThe same for <Name>Gateway, and m.import(ulo_ws::WsModule::for_root()); once per application
resolverA comment: add the resolver to the query root's #[derive(MergedObject)]

A kind that needs a crate the project may not have prints its Cargo.toml line: ulo-http or ulo-rpc for a controller, ulo-ws for a gateway, async-graphql = "7" for a resolver. Each generated file carries a test.

ulo dev

ulo dev [options] [-- <application arguments>]

Runs the project and restarts it when a .rs or .toml file changes. It must be run from a directory with a Cargo.toml. It builds with cargo build and starts the binary the build reports. Cargo's selection flags apply to the build and everything after -- goes to the application. Behaviour while a rebuild runs, and a failed build, is on Development Workflow.

Options:

OptionMeaning
--releaseBuild and run in release mode
-p, --package <SPEC>Package to run, for a workspace with more than one
--bin <NAME>Run this binary instead of the package default
--example <NAME>Run this example instead of a binary; refused with --bin
-F, --features <FEATURES>Features to activate; repeat the flag or comma-separate the list
--all-featuresActivate every feature of every selected package
--no-default-featuresDo not activate the default feature
--cargo-arg <ARG>Forward one argument to cargo as given; repeat it once per argument
--listen <ADDR>Hold a listening TCP socket on ADDR across restarts. Unix only
ulo dev --release -p my-app
ulo dev -p my-app --example demo -F tls -- --config config/local.toml
ulo dev --cargo-arg --offline --cargo-arg --timings

Target and feature selectors go before the --. The cargo command is assembled in a fixed order: build, --release, the --package, --bin and --example selectors, --features, --all-features, --no-default-features, then the --cargo-arg values in the order given.

--listen

--listen ADDR binds ADDR once and passes the socket to every child as file descriptor 3 with LISTEN_FDS=1, LISTEN_FDNAMES and LISTEN_PID, set through a trampoline (ulo __exec, hidden) so the process ID matches the child's. Every child also runs with ULO_DEV=1, under which a server written with the same address adopts the held socket. Connections arriving while no child accepts queue in the socket's backlog.

  • ADDR is a socket address with a host: 127.0.0.1:3000 or 0.0.0.0:8080, optionally prefixed tcp://. A bare port and a udp:// address are refused.
  • A UDP link is outside --listen and binds its own address.
  • On a platform without descriptor passing the flag is ignored with a warning.

The application side is on Socket activation.

CLI Installation

Install the ulo binary from crates.io, with or without the dev command.

API Reference

The crate map, the macros, the core types, the error catalogue and the feature and environment tables.

On this page

ulo newTransportsDatabasesulo generateulo dev--listen