Structured web framework for rust built on top of axum.
Designed to build server application with less boilerplate and more simplicity.
It takes advantage of the tokio ecosystem to bring you performance with nice DX.
Sword is in active development, expect breaking changes.
- Macro-based routing - Clean and intuitive route definitions
- JSON-first design - Built with JSON formats as priority
- Built-in validation - Support
validatorcrate and extensible validation system - HTTP responses standarization - Using
axum_responsescrate - Dependency Injection - Built-in DI support
- Asynchronous by default - Built on top of
axumandtokio - Interactive CLI - Built to improve the developer experience
[dependencies]
sword = "0.2.0"use sword::prelude::*;
use serde_json::Value;
#[controller("/")]
struct AppController;
#[routes]
impl AppController {
#[get("/hello")]
async fn hello(&self) -> HttpResponse {
HttpResponse::Ok().message("Hello, World!")
}
#[post("/submit")]
async fn submit_data(&self, req: Request) -> HttpResult {
let body = req.body::<Value>()?;
Ok(HttpResponse::Ok()
.data(body)
.message("Data submitted successfully"))
}
}
#[sword::main]
async fn main() {
let app = Application::builder()
.with_controller::<AppController>()
.build();
app.run().await;
}See the examples directory for more advanced usage.
See CHANGELOG.md for more details.
Contributions are welcome! Please open an issue or submit a pull request. See CONTRIBUTING.md for more details.