Struct serde_qs::actix::QsQueryConfig
source · pub struct QsQueryConfig { /* private fields */ }
Expand description
Query extractor configuration
use actix_web::{error, web, App, FromRequest, HttpResponse};
use serde_qs::actix::QsQuery;
use serde_qs::Config as QsConfig;
use serde_qs::actix::QsQueryConfig;
#[derive(Deserialize)]
struct Info {
username: String,
}
/// deserialize `Info` from request's querystring
async fn index(info: QsQuery<Info>) -> HttpResponse {
HttpResponse::Ok().body(
format!("Welcome {}!", info.username)
)
}
fn main() {
let qs_config = QsQueryConfig::default()
.error_handler(|err, req| { // <- create custom error response
error::InternalError::from_response(
err, HttpResponse::Conflict().finish()).into()
})
.qs_config(QsConfig::default());
let app = App::new().service(
web::resource("/index.html").app_data(qs_config)
.route(web::post().to(index))
);
}
Implementations§
source§impl QsQueryConfig
impl QsQueryConfig
sourcepub fn error_handler<F>(self, f: F) -> Selfwhere
F: Fn(QsError, &HttpRequest) -> ActixError + Send + Sync + 'static,
pub fn error_handler<F>(self, f: F) -> Selfwhere F: Fn(QsError, &HttpRequest) -> ActixError + Send + Sync + 'static,
Set custom error handler