Remove 'Per-type' JsonConfig example.

This commit is contained in:
Robert G. Jakabosky 2020-09-10 21:36:23 +08:00
parent 18887ac97a
commit 35a0dae4e4
No known key found for this signature in database
GPG Key ID: 0C38AF433FE0B1C0
1 changed files with 1 additions and 48 deletions

View File

@ -209,9 +209,7 @@ where
/// Json extractor configuration
///
/// # Examples
///
/// Global extractor configuration:
/// # Example
///
/// ```rust
/// use actix_web::{error, web, App, FromRequest, HttpResponse};
@ -247,51 +245,6 @@ where
/// }
/// ```
///
/// Per-type extractor configuration:
///
/// ```rust
/// use actix_web::{error, web, App, FromRequest, HttpRequest, HttpResponse};
/// use serde_derive::Deserialize;
///
/// #[derive(Deserialize)]
/// struct Info {
/// username: String,
/// }
///
/// /// deserialize `Info` from request's body, max payload size is 4kb
/// async fn index(info: web::Json<Info>) -> String {
/// format!("Welcome {}!", info.username)
/// }
///
/// /// Return either a 400 or 415, and include the error message from serde
/// /// in the response body
/// fn json_error_handler(err: error::JsonPayloadError, _req: &HttpRequest) -> error::Error {
/// let detail = err.to_string();
/// let response = match &err {
/// error::JsonPayloadError::ContentType => {
/// HttpResponse::UnsupportedMediaType().content_type("text/plain").body(detail)
/// }
/// _ => HttpResponse::BadRequest().content_type("text/plain").body(detail),
/// };
/// error::InternalError::from_response(err, response).into()
/// }
///
/// fn main() {
/// let app = App::new().service(
/// web::resource("/index.html")
/// .app_data(
/// // JSON extractor configuration for the `Info` struct only.
/// web::Json::<Info>::configure(|cfg| {
/// cfg.limit(4096)
/// .content_type(|mime| { // <- accept text/plain content type
/// mime.type_() == mime::TEXT && mime.subtype() == mime::PLAIN
/// })
/// .error_handler(json_error_handler) // Use our custom error response
/// }))
/// .route(web::post().to(index))
/// );
/// }
/// ```
#[derive(Clone)]
pub struct JsonConfig {
limit: usize,