cirro
A lightweight Rust library for building server-rendered websites with Mustache templates, powered by axum.
Features
- Route builder API
- Mustache templating using ramhorns
- In-memory page cache with TTL and tag-based invalidation
- Parameterised and catch-all route patterns (
{param}, {*catchall})
Quick start
use cirro::{App, CacheConfig, Route};
use serde_json::json;
use std::time::Duration;
#[tokio::main]
async fn main() {
let app = App::new()
.template_dir("templates")
.register(
Route::new("/")
.template("index.mustache")
.cache(CacheConfig::new().ttl(Duration::from_secs(60)).tag("home"))
.data(|_params| async { json!({ "title": "Home" }) }),
)
.register(
Route::new("/blog/{slug}")
.template("blog/post.mustache")
.cache(CacheConfig::new().ttl(Duration::from_secs(300)).tag("blog"))
.data(|params| async move {
let slug = params.get("slug").cloned().unwrap_or_default();
json!({ "title": format!("Post: {slug}"), "slug": slug })
}),
);
app.serve("0.0.0.0:3000").await;
}
Running the demo
cargo run --example demo