mirror of
https://github.com/actix/actix-website
synced 2024-12-04 04:31:55 +01:00
20 lines
382 B
Rust
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>
|