api-version

Crates.ioapi-version
lib.rsapi-version
version0.3.4
created_at2025-03-14 15:39:30.955028+00
updated_at2026-01-07 14:25:46.346139+00
descriptionAxum middleware to add a version prefix to request paths based on a set of versions and an optional `x-api-version` header
homepagehttps://github.com/hseeberger/api-version
repositoryhttps://github.com/hseeberger/api-version
max_upload_size
id1592379
size65,310
Heiko Seeberger (hseeberger)

documentation

https://github.com/hseeberger/api-version

README

api-version

license build docs

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.

Example

const API_VERSIONS: ApiVersions<2> = ApiVersions::new([0, 1]);

let app = Router::new()
    .route("/ready", get(ready))
    .route("/api/v0/test", get(ok_0))
    .route("/api/v1/test", get(ok_1));

let mut app = ApiVersionLayer::new("/api", API_VERSIONS).layer(app);

License

This code is open source software licensed under the Apache 2.0 License.

Commit count: 132

cargo fmt