pub struct ApiVersionLayer<const N: usize, F> { /* 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.
Notice that paths starting with a valid 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, F> ApiVersionLayer<N, F>
impl<const N: usize, F> ApiVersionLayer<N, F>
Sourcepub fn new(versions: ApiVersions<N>, filter: F) -> Self
pub fn new(versions: ApiVersions<N>, filter: F) -> Self
Create a new API version layer.
Trait Implementations§
Source§impl<const N: usize, F: Clone> Clone for ApiVersionLayer<N, F>
impl<const N: usize, F: Clone> Clone for ApiVersionLayer<N, F>
Source§fn clone(&self) -> ApiVersionLayer<N, F>
fn clone(&self) -> ApiVersionLayer<N, F>
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 moreSource§impl<const N: usize, S, F> Layer<S> for ApiVersionLayer<N, F>where
F: ApiVersionFilter,
impl<const N: usize, S, F> Layer<S> for ApiVersionLayer<N, F>where
F: ApiVersionFilter,
Auto Trait Implementations§
impl<const N: usize, F> Freeze for ApiVersionLayer<N, F>where
F: Freeze,
impl<const N: usize, F> RefUnwindSafe for ApiVersionLayer<N, F>where
F: RefUnwindSafe,
impl<const N: usize, F> Send for ApiVersionLayer<N, F>where
F: Send,
impl<const N: usize, F> Sync for ApiVersionLayer<N, F>where
F: Sync,
impl<const N: usize, F> Unpin for ApiVersionLayer<N, F>where
F: Unpin,
impl<const N: usize, F> UnwindSafe for ApiVersionLayer<N, F>where
F: UnwindSafe,
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