1
0
mirror of https://github.com/actix/actix-website synced 2024-12-03 20:22:13 +01:00
actix-website/examples/responses/src/json_resp.rs
2019-06-17 15:15:33 -04:00

20 lines
382 B
Rust

// <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>