For AI agents: the complete documentation index is available at https://a3s-lab.github.io/Boot/en/llms.txt, the full documentation bundle is available at https://a3s-lab.github.io/Boot/en/llms-full.txt, and this page is available as Markdown at https://a3s-lab.github.io/Boot/en/getting-started/quick-start.md.
  • English
  • v0.2.0
  • Quick start

    This example registers one singleton provider, one controller, and one GET route with a path parameter. It only uses default features.

    1. Add dependencies

    Cargo.toml
    [package]
    name = "boot-hello"
    version = "0.1.0"
    edition = "2021"
    
    [dependencies]
    a3s-boot = "0.2.0"
    tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

    2. Declare a provider and controller

    src/main.rs
    use std::sync::Arc;
    
    use a3s_boot::{
        controller, get, injectable, module, param, AxumAdapter, BootFactory, Result,
    };
    
    #[injectable]
    #[derive(Debug)]
    struct GreetingService;
    
    impl GreetingService {
        fn hello(&self, name: &str) -> String {
            format!("Hello, {name}")
        }
    }
    
    #[injectable]
    #[derive(Debug)]
    struct GreetingController {
        greeting: Arc<GreetingService>,
    }
    
    #[controller("/greetings")]
    impl GreetingController {
        #[get("/{name}")]
        async fn greet(&self, #[param("name")] name: String) -> Result<String> {
            Ok(self.greeting.hello(&name))
        }
    }
    
    #[module(
        name = "app",
        providers = [GreetingService, GreetingController],
        controllers = [GreetingController],
    )]
    #[derive(Debug)]
    struct AppModule;
    
    #[tokio::main]
    async fn main() -> Result<()> {
        let mut app = BootFactory::create(AppModule)?;
        app.listen_with(&AxumAdapter::new(), ([127, 0, 0, 1], 3000).into())
            .await
    }

    #[injectable] generates a FromModuleRef implementation for an ordinary Rust type. The Arc<GreetingService> field on GreetingController becomes an explicit dependency. The module registers the controller as both a provider and an HTTP controller.

    3. Run and call the route

    cargo run

    In another terminal:

    curl http://127.0.0.1:3000/greetings/A3S

    The response body is:

    Hello, A3S

    What happened during construction

    1. BootFactory::create collected the AppModule declarations.
    2. The container checked provider tokens, dependencies, and module visibility.
    3. Controller macros generated ControllerDefinition and RouteDefinition values.
    4. The Axum adapter converted framework routes into a concrete router.
    5. The request entered the Boot pipeline, the path parameter became a String, and the handler ran.

    Missing dependencies, duplicate routes, and invalid module graphs return a BootError before the server listens.

    The explicit API remains available

    Attribute macros are not a second runtime. Dynamic applications and projects that avoid procedural macros can implement Module directly and return ProviderDefinition and ControllerDefinition values. Both styles enter the same application graph and execution pipeline.

    Next steps