pub struct ApiVersionLayer<const N: usize> { /* private fields */ }Expand description
Axum middleware to rewrite a request such that a version prefix is added to the path. This is
based on a set of API versions and an optional "x-api-version" custom HTTP header: if no such
header is present, the highest version is used. Yet this only applies to requests the URIs of
which pass a filter; others are not rewritten. Also, paths starting with a valid/existing
version prefix, e.g. "/v0", are not rewritten.
§Examples
The middleware needs to be applied to the “root” router:
ⓘ
let app = Router::new()
.route("/", get(ok_0))
.route("/v0/test", get(ok_0))
.route("/v1/test", get(ok_1))
.route("/foo", get(ok_foo));
const API_VERSIONS: ApiVersions<2> = ApiVersions::new([0, 1]);
let mut app = ApiVersionLayer::new(API_VERSIONS, FooFilter).layer(app);Implementations§
Source§impl<const N: usize> ApiVersionLayer<N>
impl<const N: usize> ApiVersionLayer<N>
Sourcepub fn new(base_path: impl AsRef<str>, versions: ApiVersions<N>) -> Self
pub fn new(base_path: impl AsRef<str>, versions: ApiVersions<N>) -> Self
Create a new API version layer.
Trait Implementations§
Source§impl<const N: usize> Clone for ApiVersionLayer<N>
impl<const N: usize> Clone for ApiVersionLayer<N>
Source§fn clone(&self) -> ApiVersionLayer<N>
fn clone(&self) -> ApiVersionLayer<N>
Returns a duplicate 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 moreAuto Trait Implementations§
impl<const N: usize> Freeze for ApiVersionLayer<N>
impl<const N: usize> RefUnwindSafe for ApiVersionLayer<N>
impl<const N: usize> Send for ApiVersionLayer<N>
impl<const N: usize> Sync for ApiVersionLayer<N>
impl<const N: usize> Unpin for ApiVersionLayer<N>
impl<const N: usize> UnwindSafe for ApiVersionLayer<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more