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:
@ -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]
|
||||
|
Reference in New Issue
Block a user