Expand description
§Axeon
A modern, flexible, and feature-rich web framework for Rust.
§Features
- Express-style routing with support for path parameters and query parameters
- Modular router system with mounting capabilities
- Powerful middleware system for request/response processing
- Built-in security features and authentication support
- JSON request/response handling with type safety
- Async/await support throughout the framework
§Quick Start
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");
}
§Routing Examples
§Basic Routes
use axeon::{Response, Server};
let mut app = Server::new();
// Basic 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))
});
§JSON Handling
use axeon::{Response, Server, ServerError};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct User {
name: String,
role: String,
}
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())),
}
});
§Middleware System
use axeon::{Request, Response, ServerError};
use axeon::middleware::{Middleware, MiddlewareResult, Next};
use std::time::Instant;
// Example logging middleware
struct Logger;
impl Middleware for Logger {
fn call(&self, req: Request, next: Next) -> MiddlewareResult {
Box::pin(async move {
let start = Instant::now();
let method = req.method.clone();
let url = req.path.clone();
let res = next.handle(req).await;
let status = match &res {
Ok(res) => res.status,
Err(err) => err.status_code(),
};
println!("[{}] {:?} {} - {}ms", status, method, url, start.elapsed().as_millis());
res
})
}
fn clone_box(&self) -> Box<dyn Middleware> {
Box::new(Self)
}
}
§Router Groups
use axeon::{Router, Server, Response};
let mut app = Server::new();
let mut api = Router::new();
// API routes
api.get("/status", |_req| async {
Response::ok(&serde_json::json!({
"status": "operational",
"version": "1.0.0"
}))
});
// Mount API routes with prefix
app.mount("/api", api);
Re-exports§
pub extern crate serde_json;
Modules§
Macros§
- created_
json - json
- Construct a
serde_json::Value
from a JSON literal. - middlewares
- ok_json
Structs§
Enums§
- Method
- Parse
Error - Server
Error - Value
- Represents any valid JSON value.