Struct actix_web::web::QueryConfig [−][src]
pub struct QueryConfig { /* fields omitted */ }
Expand description
Query extractor configuration
Example
use actix_web::{error, web, App, FromRequest, HttpResponse};
use serde_derive::Deserialize;
#[derive(Deserialize)]
struct Info {
username: String,
}
/// deserialize `Info` from request's querystring
async fn index(info: web::Query<Info>) -> String {
format!("Welcome {}!", info.username)
}
fn main() {
let app = App::new().service(
web::resource("/index.html").app_data(
// change query extractor configuration
web::QueryConfig::default()
.error_handler(|err, req| { // <- create custom error response
error::InternalError::from_response(
err, HttpResponse::Conflict().finish()).into()
})
)
.route(web::post().to(index))
);
}
Implementations
pub fn error_handler<F>(self, f: F) -> Self where
F: Fn(QueryPayloadError, &HttpRequest) -> Error + Send + Sync + 'static,
pub fn error_handler<F>(self, f: F) -> Self where
F: Fn(QueryPayloadError, &HttpRequest) -> Error + Send + Sync + 'static,
Set custom error handler
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for QueryConfig
impl Send for QueryConfig
impl Sync for QueryConfig
impl Unpin for QueryConfig
impl !UnwindSafe for QueryConfig
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more