Smeltery
Get started

Getting started

v0.1

Wiring: bootstrap/app.rs

rust
use smeltery::AppBuilder;
use smeltery::middleware::{Next, Request};
use smeltery::Response;

#[derive(Clone)]
pub struct AppConfig {
    pub name: String,
}

async fn log_requests(req: Request, next: Next) -> Response {
    let path = req.uri().path().to_owned();
    let res = next.run(req).await;
    println!("{path} -> {}", res.status());
    res
}

async fn home() -> &'static str { "home" }

pub fn build(app: AppBuilder) -> AppBuilder {
    app.config(AppConfig { name: "Demo".into() })
        .middleware("log", log_requests)
        .routes(|r| {
            r.get("/", home).name("home").middleware("log");
        })
}
  • config(value) / service(value) register a value by type; handlers take Config<T>, other code calls app.config::<T>() / app.service::<T>().
  • middleware(alias, f) registers route middleware; global_middleware(f) runs on every request; middleware_family(prefix, make) registers aliases with arguments (see Routes and controllers).
  • on_boot(|app| async move { … }) runs async setup (open connections, register services) before the server starts.
  • migrations(register), seeders(register) and commands(register) take the register functions of database/migrations, database/seeders and app/commands.
  • auth::<User>() (one model per app: two different models stop the app at boot) makes User the model Auth signs in and registers the web guard and the auth, guest, verified and password.confirm middleware; credential_listener(l), second_factor(f), login_completion(c) and login_policy(p) register the password-change hooks, a second factor, the sign-in completion and a rule every new sign-in meets; guard(g) registers another guard (see Guards and the principal).
  • hallmark(Hallmark::new()) (smeltery::hallmark::HallmarkExt) adds API tokens and the auth:hallmark guard (see API tokens).
  • bellows() (smeltery::bellows::BellowsExt) adds the bellows:mcp command (see Bellows below).

↑↓ moveEnter openEsc close