Skip to main content

toolkit/api/
mod.rs

1//! Type-safe API operation builder with compile-time guarantees
2//!
3//! This gear provides a type-state builder pattern that enforces at compile time
4//! that API operations cannot be registered unless both a handler and at least one
5//! response are specified.
6
7pub mod api_dto;
8pub mod canonical_error_layer;
9pub mod error_layer;
10pub mod odata;
11pub mod openapi_registry;
12pub mod operation_builder;
13pub mod response;
14pub mod rest;
15pub mod select;
16
17#[cfg(test)]
18#[cfg_attr(coverage_nightly, coverage(off))]
19mod odata_policy_tests;
20
21pub use canonical_error_layer::canonical_error_middleware;
22pub use error_layer::{
23    IntoCanonical, error_mapping_middleware, extract_trace_id, map_error_to_canonical,
24};
25pub use openapi_registry::{OpenApiInfo, OpenApiRegistry, OpenApiRegistryImpl, ensure_schema};
26pub use operation_builder::{
27    Missing, OperationBuilder, OperationSpec, ParamLocation, ParamSpec, Present,
28    ResponseHeaderSpec, ResponseHeaderType, ResponseSpec, ThrottlingSpec, state,
29};
30pub use select::{apply_select, page_to_projected_json, project_json};
31
32/// Prelude that re-exports the canonical error types and common API utilities.
33pub mod canonical_prelude {
34    // Canonical error types
35    pub use toolkit_canonical_errors::{CanonicalError, Problem, resource_error};
36
37    /// Result type alias for handlers using the canonical error catalog.
38    ///
39    /// Returns [`CanonicalError`] (not [`Problem`]) so handler `?` chains
40    /// resolve through `From<DomainError> for CanonicalError` — the
41    /// long-lived per-gear mapping. The canonical error middleware
42    /// (`toolkit::api::canonical_error_middleware`) converts the
43    /// `CanonicalError` to a wire `Problem` and fills `instance` /
44    /// `trace_id` on the way out, so handlers never need to construct a
45    /// `Problem` themselves.
46    pub type ApiResult<T = ()> = std::result::Result<T, CanonicalError>;
47
48    // Same response sugar / OData / axum re-exports as the legacy prelude
49    pub use super::odata::OData;
50    pub use super::response::{JsonBody, JsonPage, created_json, no_content, ok_json};
51    pub use super::rest::extract;
52    pub use super::select::apply_select;
53    pub use axum::{Json, http::StatusCode, response::IntoResponse};
54}