| Crates.io | axeon |
| lib.rs | axeon |
| version | 0.2.0 |
| created_at | 2025-02-23 19:22:21.003381+00 |
| updated_at | 2025-02-26 04:38:25.543497+00 |
| description | A modern and flexible backend server framework for Rust |
| homepage | |
| repository | https://github.com/sketch/axeon |
| max_upload_size | |
| id | 1566588 |
| size | 125,051 |
A modern, flexible, and feature-rich web framework for Rust.
Add Axeon to your Cargo.toml:
[dependencies]
axeon = "0.2.0"
Create a simple server:
use axeon::{Response, Server};
fn main() {
let mut app = Server::new();
app.get("/", |_req| async {
Response::text("Hello, World!")
});
app.listen("127.0.0.1:3000")
.expect("Server failed to start");
}
use axeon::{Response, Server};
let mut app = Server::new();
// Basic GET route
app.get("/", |_req| async {
Response::text("Welcome!")
});
// Route with path parameter
app.get("/users/:id", |req| async move {
let user_id = req.params.get("id").unwrap();
Response::text(format!("User ID: {}", user_id))
});
use axeon::{Response, Server, ServerError};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct User {
name: String,
role: String,
}
// POST endpoint with JSON handling
app.post("/users", |req| async move {
match req.body.json::<User>() {
Some(user) => Response::ok(&user),
None => Err(ServerError::BadRequest("Invalid JSON body".to_string())),
}
});
use axeon::{Server, middleware::{Middleware, Next}};
struct Logger;
impl Middleware for Logger {
fn call(&self, req: Request, next: Next) -> MiddlewareResult {
Box::pin(async move {
// Process request...
let res = next.handle(req).await;
// Process response...
res
})
}
}
let mut app = Server::new();
app.middleware(Logger);
use axeon::{Router, Server};
let mut app = Server::new();
let mut api = Router::new();
// Define routes for the API group
api.get("/status", |_req| async {
Response::ok(&serde_json::json!({
"status": "operational"
}))
});
// Mount the API router with a prefix
app.mount("/api", api);
For detailed documentation and more examples, check out:
This project is licensed under the MIT License.