version_middleware 0.1.2

Custom extractor for Rust Axum to extract the version from an HTTP header `x-version`.
Documentation
  • Coverage
  • 33.33%
    1 out of 3 items documented1 out of 2 items with examples
  • Size
  • Source code size: 24.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 357.5 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 49s Average build duration of successful builds.
  • all releases: 52s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • fgruchala

Rust Axum Middleware - Extract Version from Header

Custom extractor for Rust Axum to extract the version from an HTTP header x-version. Works ONLY with Rust Axum.

Usage

use axum::{routing::get, Router};
use version_middleware::ExtractVersion;

async fn handler(ExtractVersion(version): ExtractVersion) {
    println!("Version: {}", version);
}

let app = Router::<()>::new().route("/foo", get(handler));

The extracted value is :

  • trim to clean extra spaces, before and after ;
  • lowercase to standardize and make it more resilient to implementation errors.

Samples

Extract version if the header is explicitly set

curl -H "X-Version: v1.0.0" http://api.nebeto.xyz/foo
curl -H "x-version: preView" http://api.nebeto.xyz/foo
curl -H "X-VeRSion: latest" http://api.nebeto.xyz/foo

Will give respectively v1.0.0, preview and latest.

Extract version if the header is missing

curl http://api.nebeto.xyz/foo

Will give by default latest.

Contact

For any question or feature suggestion, you can take a look and open, if necessary, a new discussion.

For any bug, you can take a look to our active issues and open, if necessary, a new issue.