mirror of
https://github.com/actix/examples
synced 2025-01-22 22:05:57 +01:00
multi extractor for json
This commit is contained in:
parent
73a4d9d0c9
commit
a01db994f6
@ -41,6 +41,12 @@ fn extract_item(item: Json<MyObj>) -> HttpResponse {
|
|||||||
HttpResponse::Ok().json(item.0) // <- send response
|
HttpResponse::Ok().json(item.0) // <- send response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This handler uses json extractor with limit
|
||||||
|
fn extract_item_limit((item, _req): (Json<MyObj>, HttpRequest)) -> HttpResponse {
|
||||||
|
println!("model: {:?}", &item);
|
||||||
|
HttpResponse::Ok().json(item.0) // <- send response
|
||||||
|
}
|
||||||
|
|
||||||
const MAX_SIZE: usize = 262_144; // max payload size is 256k
|
const MAX_SIZE: usize = 262_144; // max payload size is 256k
|
||||||
|
|
||||||
/// This handler manually load request payload and parse json object
|
/// This handler manually load request payload and parse json object
|
||||||
@ -104,6 +110,11 @@ fn main() {
|
|||||||
.with(extract_item)
|
.with(extract_item)
|
||||||
.limit(4096); // <- limit size of the payload
|
.limit(4096); // <- limit size of the payload
|
||||||
})
|
})
|
||||||
|
.resource("/extractor2", |r| {
|
||||||
|
r.method(http::Method::POST)
|
||||||
|
.with(extract_item_limit)
|
||||||
|
.0.limit(4096); // <- limit size of the payload
|
||||||
|
})
|
||||||
.resource("/manual", |r| r.method(http::Method::POST).f(index_manual))
|
.resource("/manual", |r| r.method(http::Method::POST).f(index_manual))
|
||||||
.resource("/mjsonrust", |r| r.method(http::Method::POST).f(index_mjsonrust))
|
.resource("/mjsonrust", |r| r.method(http::Method::POST).f(index_mjsonrust))
|
||||||
.resource("/", |r| r.method(http::Method::POST).f(index))
|
.resource("/", |r| r.method(http::Method::POST).f(index))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user