mirror of
https://github.com/actix/actix-website
synced 2024-12-03 20:22:13 +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>
|