mirror of
https://github.com/actix/actix-website
synced 2025-01-23 00:25:55 +01:00
Fixes missed example and config for extractors.
This commit is contained in:
parent
c4c32091a6
commit
339ac43814
@ -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
|
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
|
[*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
|
for configuration. To configure an extractor, pass it's configuration object to the resource's
|
||||||
configuration instance. In case of a *Json* extractor it returns a *JsonConfig*. You can
|
`.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.
|
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.
|
The following example limits the size of the payload to 4kb and uses a custom error handler.
|
||||||
|
23
examples/extractors/src/path_three.rs
Normal file
23
examples/extractors/src/path_three.rs
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user