1
0
mirror of https://github.com/actix/examples synced 2025-01-22 14:05:55 +01:00

multi extractor for json

This commit is contained in:
Nikolay Kim 2018-06-02 08:28:33 -07:00
parent 73a4d9d0c9
commit a01db994f6

View File

@ -41,6 +41,12 @@ fn extract_item(item: Json<MyObj>) -> HttpResponse {
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
/// This handler manually load request payload and parse json object
@ -104,6 +110,11 @@ fn main() {
.with(extract_item)
.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("/mjsonrust", |r| r.method(http::Method::POST).f(index_mjsonrust))
.resource("/", |r| r.method(http::Method::POST).f(index))