1
0
mirror of https://github.com/actix/actix-website synced 2025-06-27 07:29:02 +02:00

Improve json documentation (#245)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
nikstur
2021-12-05 15:41:37 +01:00
committed by GitHub
parent 1960650cb0
commit c66502c548
3 changed files with 38 additions and 31 deletions

View File

@ -1,17 +1,18 @@
// <json-resp>
use actix_web::{get, web, HttpResponse, Result};
use serde::{Deserialize, Serialize};
use actix_web::{get, web, Responder, Result};
use serde::Serialize;
#[derive(Serialize, Deserialize)]
#[derive(Serialize)]
struct MyObj {
name: String,
}
#[get("/a/{name}")]
async fn index(obj: web::Path<MyObj>) -> Result<HttpResponse> {
Ok(HttpResponse::Ok().json(MyObj {
name: obj.name.to_string(),
}))
async fn index(name: web::Path<String>) -> Result<impl Responder> {
let obj = MyObj {
name: name.to_string(),
};
Ok(web::Json(obj))
}
#[actix_web::main]