toni
Getting Started

Installation

Add Toni to a new or existing Rust project.

Prerequisites

  • Rust 1.75 or later (2024 edition is recommended)
  • Cargo

Option A — Start from a template with the CLI

The fastest way to get a working Toni project is through the CLI:

cargo install toni-cli
toni new my_app
cd my_app
cargo run

This scaffolds a project with AppModule, AppController, and AppService wired together and ready to run.

Option B — Add to an existing project

Add the core crate and your chosen HTTP adapter to Cargo.toml:

[dependencies]
toni = "0.2"

# Choose one adapter:
toni-axum = "0.1"    # Axum + Tokio  (I/O-bound workloads)
# toni-actix = "0.1" # Actix-web     (CPU-bound workloads)

# Async runtime (required with toni-axum)
tokio = { version = "1", features = ["full"] }

# Serialization (nearly always needed)
serde = { version = "1", features = ["derive"] }
serde_json = "1"

Optional crates

CratePurpose
toni-configEnvironment-based configuration with optional validation
toni-async-graphqlGraphQL via async-graphql
toni-juniperGraphQL via juniper

Minimum working main

use toni::ToniFactory;
use toni_axum::AxumAdapter;

#[tokio::main]
async fn main() {
    let adapter = AxumAdapter::new();
    let mut app = ToniFactory::create(AppModule, adapter).await;
    app.listen(3000, "127.0.0.1").await;
}

That's it. Everything else — modules, controllers, services — lives in your application code and gets wired together by the DI container at startup.

On this page