1
0
mirror of https://github.com/actix/actix-website synced 2025-01-22 16:15:56 +01:00

Fixes missed example and config for extractors.

This commit is contained in:
Cameron Dershem 2019-06-20 04:26:34 -04:00
parent c4c32091a6
commit 339ac43814
2 changed files with 25 additions and 2 deletions

View File

@ -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.

View File

@ -0,0 +1,23 @@
use actix_web::{web, App, HttpRequest, HttpServer, Result};
// <path-three>
fn index(req: HttpRequest) -> Result<String> {
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();
}
// </path-three>