Skip to main content

modkit/api/
mod.rs

1//! Type-safe API operation builder with compile-time guarantees
2//!
3//! This module 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 error_layer;
9pub mod odata;
10pub mod openapi_registry;
11pub mod operation_builder;
12pub mod problem;
13pub mod response;
14pub mod select;
15pub mod trace_layer;
16
17#[cfg(test)]
18#[cfg_attr(coverage_nightly, coverage(off))]
19mod odata_policy_tests;
20
21pub use error_layer::{
22    IntoProblem, error_mapping_middleware, extract_trace_id, map_error_to_problem,
23};
24pub use openapi_registry::{OpenApiInfo, OpenApiRegistry, OpenApiRegistryImpl, ensure_schema};
25pub use operation_builder::{
26    Missing, OperationBuilder, OperationSpec, ParamLocation, ParamSpec, Present, RateLimitSpec,
27    ResponseSpec, state,
28};
29pub use problem::{
30    APPLICATION_PROBLEM_JSON, Problem, ValidationError, bad_request, conflict, internal_error,
31    not_found,
32};
33pub use select::{apply_select, page_to_projected_json, project_json};
34pub use trace_layer::{WithRequestContext, WithTraceContext};
35
36/// Prelude module that re-exports common API types and utilities for module authors
37pub mod prelude {
38    // Result type (Problem-only)
39    pub use crate::result::ApiResult;
40
41    // Problem type for error construction
42    pub use super::problem::Problem;
43
44    // Response sugar
45    pub use super::response::{JsonBody, JsonPage, created_json, no_content, ok_json};
46
47    // OData and field projection
48    pub use super::select::apply_select;
49
50    // Useful axum bits (common in handlers)
51    pub use axum::{Json, http::StatusCode, response::IntoResponse};
52}