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