use allframe_core::{
prelude::*,
router::{OpenApiGenerator, ScalarConfig, ScalarTheme},
};
#[tokio::main]
async fn main() {
let mut router = Router::new();
router.get("/users", || async { "Users list".to_string() });
router.post("/users", || async { "User created".to_string() });
router.get("/health", || async { "OK".to_string() });
let openapi = OpenApiGenerator::new("AllFrame API", "1.0.0")
.with_description("Full-featured API with Scalar documentation")
.with_server("http://localhost:3000", Some("Development"))
.with_server("https://api.example.com", Some("Production"))
.with_server("https://staging.example.com", Some("Staging"))
.generate(&router);
let openapi_json =
serde_json::to_string_pretty(&openapi).expect("Failed to serialize OpenAPI spec");
let scalar_config = ScalarConfig::new()
.theme(ScalarTheme::Dark)
.show_sidebar(true)
.cdn_url("https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.25.0")
.proxy_url("https://proxy.scalar.com")
.custom_css(
r#"
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
.api-reference {
--scalar-color-accent: #4f46e5;
}
"#,
);
let _scalar_html =
allframe_core::router::scalar_html(&scalar_config, "AllFrame API", &openapi_json);
println!("Router handlers: {}", router.handlers_count());
if let Some(servers) = openapi.get("servers").and_then(|s| s.as_array()) {
println!("Servers configured: {}", servers.len());
for server in servers {
let url = server["url"].as_str().unwrap_or("unknown");
let desc = server
.get("description")
.and_then(|d| d.as_str())
.unwrap_or("No description");
println!(" - {} ({})", url, desc);
}
}
println!("All features example complete");
println!("Scalar features: CDN pinning, CORS proxy, custom theme, 'Try It' enabled");
}