json/json.rs
1use expressjs::prelude::*;
2use serde_json::json;
3
4#[tokio::main]
5async fn main() {
6 let mut app = express();
7
8 app.get("/json", async |_req, res| {
9 res.send_json(&json!({
10 "status": "success",
11 "message": "Hello from JSON!",
12 "data": {
13 "id": 1,
14 "name": "Aragorn",
15 "role": "King"
16 }
17 }))
18 });
19
20 app.listen(9000, async |port| {
21 println!("🚀 Server running on http://localhost:{port}/json");
22 })
23 .await;
24}