diff --git a/guide/src/qs_7.md b/guide/src/qs_7.md index 886d8b27c..04e6d4263 100644 --- a/guide/src/qs_7.md +++ b/guide/src/qs_7.md @@ -256,8 +256,9 @@ A full example is available in the Actix provides support for *application/x-www-form-urlencoded* encoded bodies. `HttpResponse::urlencoded()` returns a [*UrlEncoded*](../actix_web/dev/struct.UrlEncoded.html) future, which resolves -into `HashMap` which contains decoded parameters. -The *UrlEncoded* future can resolve into a error in several cases: +to the deserialized instance, the type of the instance must implement the +`Deserialize` trait from *serde*. The *UrlEncoded* future can resolve into +a error in several cases: * content type is not `application/x-www-form-urlencoded` * transfer encoding is `chunked`. @@ -268,14 +269,20 @@ The *UrlEncoded* future can resolve into a error in several cases: ```rust # extern crate actix_web; # extern crate futures; +#[macro_use] extern crate serde_derive; use actix_web::*; use futures::future::{Future, ok}; +#[derive(Deserialize)] +struct FormData { + username: String, +} + fn index(mut req: HttpRequest) -> Box> { - req.urlencoded() // <- get UrlEncoded future + req.urlencoded::() // <- get UrlEncoded future .from_err() - .and_then(|params| { // <- url encoded parameters - println!("==== BODY ==== {:?}", params); + .and_then(|data| { // <- deserialized instance + println!("USERNAME: {:?}", data.username); ok(HttpResponse::Ok().into()) }) .responder() @@ -283,7 +290,6 @@ fn index(mut req: HttpRequest) -> Box> { # fn main() {} ``` - ## Streaming request *HttpRequest* is a stream of `Bytes` objects. It can be used to read the request diff --git a/src/extractor.rs b/src/extractor.rs index dd4511ede..0b264589f 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -287,7 +287,6 @@ mod tests { } } - #[derive(Deserialize)] struct MyStruct { key: String,