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

20 lines
382 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(),
}))
}
fn main() {
App::new().route(r"/a/{name}", web::get().to(index));
}
// </json-resp>