1
0
mirror of https://github.com/actix/actix-website synced 2024-12-04 20:51:54 +01:00
actix-website/examples/responses/src/json_resp.rs

20 lines
386 B
Rust
Raw Normal View History

2019-06-17 21:15:33 +02:00
// <json-resp>
use actix_web::{web, App, HttpRequest, Result};
use serde::Serialize;
#[derive(Serialize)]
struct MyObj {
name: String,
}
fn index(req: HttpRequest) -> Result<web::Json<MyObj>> {
Ok(web::Json(MyObj {
name: req.match_info().query("name").to_string(),
}))
}
pub fn main() {
2019-06-17 21:15:33 +02:00
App::new().route(r"/a/{name}", web::get().to(index));
}
// </json-resp>