1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! Ruffus - Fast, minimalist web framework for Rust
//!
//! Ruffus is a web framework inspired by Express.js that provides a simple,
//! ergonomic API for building web applications in Rust.
//!
//! # Features
//!
//! - **Express-like API**: Familiar, intuitive routing and middleware system
//! - **Type-safe extractors**: Extract path parameters, query strings, and JSON bodies with compile-time safety
//! - **Async/await support**: Built on Tokio and Hyper for high-performance async I/O
//! - **Flexible middleware**: Composable middleware for cross-cutting concerns
//! - **Router mounting**: Organize routes with prefixes and nested routers
//!
//! # Quick Start
//!
//! ```no_run
//! use ruffus::{App, Request, Response};
//!
//! #[tokio::main]
//! async fn main() {
//! let mut app = App::new();
//!
//! app.get("/", |_req: Request| async {
//! Ok(Response::text("Hello, World!".to_string()))
//! });
//!
//! app.listen("127.0.0.1:3000").await.unwrap();
//! }
//! ```
//!
//! # Path Parameters
//!
//! Extract dynamic segments from URLs:
//!
//! ```no_run
//! # use ruffus::{App, Request, Response};
//! # #[tokio::main]
//! # async fn main() {
//! # let mut app = App::new();
//! app.get("/users/:id", |req: Request| async move {
//! let id = req.param("id").unwrap();
//! Ok(Response::text(format!("User ID: {}", id)))
//! });
//! # }
//! ```
//!
//! # JSON Handling
//!
//! Automatically serialize and deserialize JSON:
//!
//! ```no_run
//! # use ruffus::{App, Request, Response};
//! # use serde::{Deserialize, Serialize};
//! #
//! #[derive(Deserialize)]
//! struct CreateUser {
//! name: String,
//! email: String,
//! }
//!
//! #[derive(Serialize)]
//! struct User {
//! id: u64,
//! name: String,
//! email: String,
//! }
//!
//! # #[tokio::main]
//! # async fn main() {
//! # let mut app = App::new();
//! app.post("/users", |mut req: Request| async move {
//! let body: CreateUser = req.json().await?;
//! let user = User {
//! id: 1,
//! name: body.name,
//! email: body.email,
//! };
//! Response::json(&user)
//! });
//! # }
//! ```
//!
//! # Middleware
//!
//! Add cross-cutting functionality with middleware:
//!
//! ```no_run
//! # use ruffus::{App, Request, Response, Middleware, Next};
//! # use async_trait::async_trait;
//! # use std::sync::Arc;
//! #
//! struct Logger;
//!
//! #[async_trait]
//! impl Middleware for Logger {
//! async fn handle(&self, req: Request, next: Next) -> ruffus::Result<Response> {
//! println!("{} {}", req.method(), req.uri());
//! next.run(req).await
//! }
//! }
//!
//! # #[tokio::main]
//! # async fn main() {
//! # let mut app = App::new();
//! app.use_middleware(Arc::new(Logger));
//! # }
//! ```
//!
//! # Routers
//!
//! Organize routes with common prefixes:
//!
//! ```no_run
//! # use ruffus::{App, Router, Request, Response};
//! # #[tokio::main]
//! # async fn main() {
//! let mut api = Router::new("/api");
//!
//! api.get("/users", |_req: Request| async {
//! Ok(Response::json(&serde_json::json!({"users": []}))?)
//! });
//!
//! api.post("/users", |mut req: Request| async move {
//! // Handle user creation
//! Ok(Response::json(&serde_json::json!({"status": "created"}))?)
//! });
//!
//! let mut app = App::new();
//! app.mount("/", api);
//! // Routes are now available at /api/users
//! # }
//! ```
// Re-export main types for convenience
pub use App;
pub use Error;
pub use ;
pub use Method;
pub use ;
pub use Request;
pub use Response;
pub use ;
pub type Result<T> = Result;