json/
json.rs

1use serde::{Deserialize, Serialize};
2
3use aero::Aero;
4use aero::Context;
5use aero::Next;
6use aero::Router;
7
8#[derive(Serialize, Deserialize)]
9pub struct Book {
10    id: i32,
11    name: String,
12    price: f32,
13}
14
15fn main() {
16    let mut app = Aero::new("127.0.0.1:3000");
17
18    let mut router = Router::new("/api");
19    router.get("/book", |ctx: &mut Context, next: Next| {
20        ctx.send_json(Book {
21            id: 123,
22            name: "asd".to_string(),
23            price: 123.3,
24        });
25        next(ctx);
26    });
27    app.mount(router);
28
29    app.get("/hello", |ctx: &mut Context, next: Next| {
30        ctx.send_text("Hello, world!");
31    });
32
33    println!("Listening on http://{}", app.socket_addr);
34
35    tokio::runtime::Builder::new_multi_thread()
36        // .worker_threads(6)
37        .enable_all()
38        .build()
39        .unwrap()
40        .block_on(app.run());
41}