-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.rs
More file actions
31 lines (25 loc) · 802 Bytes
/
basic.rs
File metadata and controls
31 lines (25 loc) · 802 Bytes
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
//! Basic example of a Ruffus server
use ruffus::{App, Request, Response};
#[tokio::main]
async fn main() {
let mut app = App::new();
// Simple GET route
app.get("/", |_req: Request| async {
Ok(Response::text("Hello, Ruffus!".to_string()))
});
// Route with path parameter
app.get("/hello/:name", |req: Request| async move {
let name = req.param("name").unwrap_or("World");
Ok(Response::text(format!("Hello, {}!", name)))
});
// JSON response
app.get("/json", |_req: Request| async {
use serde_json::json;
Response::json(&json!({
"message": "Hello from Ruffus!",
"version": "0.1.0"
}))
});
println!("Starting Ruffus server...");
app.listen("127.0.0.1:3000").await.unwrap();
}