remove_empty_query_params

Crates.ioremove_empty_query_params
lib.rsremove_empty_query_params
version0.1.1
sourcesrc
created_at2023-07-02 06:29:23.269337
updated_at2023-07-06 06:48:58.282364
descriptiontower middleware to remove empty query parameters
homepage
repositoryhttps://github.com/mingtaoy/remove_empty_query_params
max_upload_size
id905884
size6,310
Mingtao Yang (mingtaoy)

documentation

README

no_empty_query_params

Sumary

Middleware layer that removes params with empty values.

Motivation

In nginx configuration, when rewriting URLs (e.g. to pass to the upstream server), query params can be interpolated using $arg_

Example:

proxy_pass http://upstream/some/route?format=$arg_param;

Axum makes it easy to write handlers that automatically deserialize the query parameters:

#[derive(Deserialize)]
enum Format {
    Json,
    Html,
    Text
}

#[derive(Deserialize)]
struct RouteArgs {
    format: Option<Format>
}

Annoyingly, the above example will fail. Since format= is always unconditionally passed to the handler via the nginx configuratio, the default deserialization will try to deserialize Format from "".

Commit count: 3

cargo fmt