pub struct QueryStringConfig { /* private fields */ }
Expand description
QueryString extractor configuration
Example
use actix_web::{error, web, App, FromRequest, HttpResponse};
use serde::Deserialize;
use serde_querystring_actix::{QueryString, QueryStringConfig, ParseMode};
#[derive(Deserialize)]
struct Info {
username: String,
}
/// deserialize `Info` from request's querystring
async fn index(info: QueryString<Info>) -> String {
format!("Welcome {}!", info.username)
}
fn main() {
let app = App::new().service(
web::resource("/index.html").app_data(
// change query extractor configuration
QueryStringConfig::default()
.parse_mode(ParseMode::Brackets) // <- choose the parsing mode
.error_handler(|err, req| { // <- create custom error response
error::InternalError::from_response(
err, HttpResponse::Conflict().finish()).into()
})
)
.route(web::post().to(index))
);
}
Implementations§
source§impl QueryStringConfig
impl QueryStringConfig
sourcepub fn error_handler<F>(self, f: F) -> Selfwhere
F: Fn(QueryStringPayloadError, &HttpRequest) -> Error + Send + Sync + 'static,
pub fn error_handler<F>(self, f: F) -> Selfwhere
F: Fn(QueryStringPayloadError, &HttpRequest) -> Error + Send + Sync + 'static,
Set custom error handler
pub fn parse_mode(self, mode: ParseMode) -> Self
Trait Implementations§
source§impl Clone for QueryStringConfig
impl Clone for QueryStringConfig
source§fn clone(&self) -> QueryStringConfig
fn clone(&self) -> QueryStringConfig
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more