Skip to main content

cratestack_axum/
lib.rs

1//! Axum-bound runtime helpers for cratestack.
2//!
3//! The crate is organized into themed modules; see each for details:
4//!
5//! - [`codec`]: codec-bound encode/decode and the [`CodecSet`] pairing.
6//! - [`transport`]: the [`HttpTransport`] trait and the
7//!   `encode_transport_*` response family.
8//! - [`headers`]: request-header helpers (ETag, traceparent, client IP).
9//! - [`query`]: URL query parsing and the filter expression grammar.
10//! - [`rpc`]: the RPC binding (`POST /rpc/{op_id}` and
11//!   `POST /rpc/batch`).
12//! - [`compact_layer`]: the compact-wire-keys layer (integer keys for
13//!   schema field names, negotiated by media type and `Cratestack-Contract`).
14//! - [`idempotency`]: idempotency-key middleware and storage trait.
15//! - `middleware_error` (private): the shared, codec-negotiated error
16//!   envelope both middleware layers emit (cratestack#846).
17//! - [`ratelimit`]: token-bucket rate-limit middleware and storage trait.
18//! - `envelope_layer` (feature `envelope`, or `cose` for the COSE envelope
19//!   too): the server envelope layer that opens signed requests and seals
20//!   responses (ADR 0006, cratestack#1006).
21//! - [`schema_fingerprint`]: warn-only client/server schema drift
22//!   detection via the `x-cratestack-schema-sha` header.
23//! - [`trusted_proxy`]: the [`TrustedProxyConfig`] allowlist/hop-count/
24//!   [`ForwardedHeader`] type consumers apply as an `Extension` to make
25//!   `Forwarded`/`X-Forwarded-For` trust explicit (#415).
26
27pub use axum;
28/// The COSE envelope (`CoseEnvelope`, its signers and key resolvers), for
29/// building the layer's envelope without a direct `cratestack-cose`
30/// dependency. Feature `cose`.
31#[cfg(feature = "cose")]
32pub use cratestack_cose as cose;
33
34mod auth_challenge;
35pub mod codec;
36pub mod compact_layer;
37#[cfg(feature = "envelope")]
38pub mod envelope_layer;
39pub mod headers;
40pub mod idempotency;
41mod middleware_error;
42pub mod projection;
43pub mod query;
44pub mod ratelimit;
45pub mod rpc;
46pub mod schema_fingerprint;
47pub mod transport;
48pub mod trusted_proxy;
49
50// -----------------------------------------------------------------------------
51// Crate-root re-exports — every item the `cratestack-macros` crate references
52// from `cratestack_axum::*` must remain importable from the crate root. The
53// list below is explicit (not `pub use module::*;`) so the public surface is
54// greppable from this file.
55// -----------------------------------------------------------------------------
56
57pub use codec::{
58    CodecSet, decode_codec_request, encode_codec_response, encode_codec_result,
59    encode_codec_result_with_status, validate_codec_request_headers,
60    validate_codec_response_headers,
61};
62
63pub use transport::{
64    CBOR_SEQUENCE_CONTENT_TYPE, HttpTransport, decode_transport_request_for,
65    encode_transport_result, encode_transport_result_with_status,
66    encode_transport_result_with_status_for, encode_transport_sequence_result,
67    encode_transport_sequence_result_with_status, encode_transport_sequence_result_with_status_for,
68    encode_transport_stream_result_with_status_for, validate_transport_request_headers,
69    validate_transport_request_headers_for, validate_transport_response_headers,
70    validate_transport_response_headers_for,
71};
72
73pub use headers::{
74    ClientIpContext, enrich_context_from_envelope, enrich_context_from_headers, parse_client_ip,
75    parse_if_match_version, parse_traceparent, set_version_etag,
76};
77
78pub use projection::ProjectedValue;
79
80pub use query::{
81    QueryExpr, parse_computed_params_object, parse_filter_expression, parse_query_pairs,
82};
83
84pub use trusted_proxy::{ForwardedHeader, TrustedProxyConfig};