1
0
mirror of https://github.com/actix/actix-website synced 2025-03-16 05:02:45 +01:00
nikstur c66502c548
Improve json documentation (#245)
Co-authored-by: Rob Ede <robjtede@icloud.com>
2021-12-05 14:41:37 +00:00

28 lines
546 B
Rust

// <json-resp>
use actix_web::{get, web, Responder, Result};
use serde::Serialize;
#[derive(Serialize)]
struct MyObj {
name: String,
}
#[get("/a/{name}")]
async fn index(name: web::Path<String>) -> Result<impl Responder> {
let obj = MyObj {
name: name.to_string(),
};
Ok(web::Json(obj))
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{App, HttpServer};
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
.run()
.await
}
// </json-resp>