Skip to main content

Module header_id

Module header_id 

Source
Expand description

Shared HeaderId trait for newtype wrappers that are transported via a dedicated HTTP header.

All ID newtypes in this crate — crate::request_id::RequestId, crate::correlation_id::CorrelationId, crate::idempotency::IdempotencyKey, and crate::traceparent::TraceContext — follow the same pattern:

  • They carry a fixed, well-known header name.
  • They expose their value as a string.

HeaderId makes that pattern explicit and enables generic middleware or helper utilities that work over any of these types.

§Example

use api_bones::header_id::HeaderId;
use api_bones::request_id::RequestId;
use api_bones::correlation_id::CorrelationId;
use api_bones::idempotency::IdempotencyKey;
use api_bones::traceparent::TraceContext;

fn header_name_of<T: HeaderId>() -> &'static str {
    T::HEADER_NAME
}

assert_eq!(header_name_of::<RequestId>(), "X-Request-Id");
assert_eq!(header_name_of::<CorrelationId>(), "X-Correlation-Id");
assert_eq!(header_name_of::<IdempotencyKey>(), "Idempotency-Key");
assert_eq!(header_name_of::<TraceContext>(), "traceparent");

Traits§

HeaderId
A type that is transported as a single HTTP header value.