From 339ac4381422ec35ba5d26b4b41b40879ca6f6fb Mon Sep 17 00:00:00 2001 From: Cameron Dershem Date: Thu, 20 Jun 2019 04:26:34 -0400 Subject: [PATCH] Fixes missed example and config for extractors. --- content/docs/extractors.md | 4 ++-- examples/extractors/src/path_three.rs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 examples/extractors/src/path_three.rs diff --git a/content/docs/extractors.md b/content/docs/extractors.md index df6c6bc..35a08ec 100644 --- a/content/docs/extractors.md +++ b/content/docs/extractors.md @@ -62,8 +62,8 @@ the type `T` must implement the `Deserialize` trait from *serde*. Some extractors provide a way to configure the extraction process. Json extractor [*JsonConfig*](https://docs.rs/actix-web/1.0.2/actix_web/web/struct.JsonConfig.html) type -for configuration. When you register a handler using `Route::with()`, it returns a -configuration instance. In case of a *Json* extractor it returns a *JsonConfig*. You can +for configuration. To configure an extractor, pass it's configuration object to the resource's +`.data()` method. In case of a *Json* extractor it returns a *JsonConfig*. You can configure the maximum size of the json payload as well as a custom error handler function. The following example limits the size of the payload to 4kb and uses a custom error handler. diff --git a/examples/extractors/src/path_three.rs b/examples/extractors/src/path_three.rs new file mode 100644 index 0000000..9ca71c9 --- /dev/null +++ b/examples/extractors/src/path_three.rs @@ -0,0 +1,23 @@ +use actix_web::{web, App, HttpRequest, HttpServer, Result}; + +// +fn index(req: HttpRequest) -> Result { + let name: String = req.match_info().get("friend").unwrap().parse().unwrap(); + let userid: i32 = req.match_info().query("userid").parse().unwrap(); + + Ok(format!("Welcome {}, userid {}!", name, userid)) +} + +pub fn main() { + HttpServer::new(|| { + App::new().route( + "/users/{userid}/{friend}", // <- define path parameters + web::get().to(index), + ) + }) + .bind("127.0.0.1:8088") + .unwrap() + .run() + .unwrap(); +} +//