Skip to main content

at_jet/
lib.rs

1//! # AT-Jet
2//!
3//! High-performance HTTP + Protobuf API framework for mobile services.
4
5// Deny unwrap() and expect() in non-test code to prevent panics
6#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used))]
7//! AT-Jet provides a clean, ergonomic way to build HTTP APIs that use Protocol Buffers
8//! for serialization - ideal for mobile clients that need efficient bandwidth usage
9//! and strong schema evolution guarantees.
10//!
11//! ## Features
12//!
13//! - **HTTP/1.1 and HTTP/2 support** via axum
14//! - **Protobuf request/response handling** with automatic content negotiation
15//! - **Dual-format support** - Protobuf for production, JSON for debugging
16//! - **CDN-friendly** design for global mobile users
17//! - **Middleware support** for authentication, logging, compression
18//! - **Type-safe routing** with compile-time guarantees
19//!
20//! ## Quick Start
21//!
22//! ```rust,ignore
23//! use at_jet::prelude::*;
24//! use bytes::Bytes;
25//!
26//! #[tokio::main]
27//! async fn main() -> anyhow::Result<()> {
28//!     let app = JetServer::new()
29//!         .route("/api/user/:id", get(get_user))
30//!         .route("/api/user", post(create_user));
31//!
32//!     app.serve("0.0.0.0:8080").await?;
33//!     Ok(())
34//! }
35//!
36//! // Dual-format: accepts both protobuf and JSON, responds based on Accept header
37//! async fn get_user(Path(id): Path<i32>) -> ProtobufResponse<User> {
38//!     let user = User { id, name: "John".to_string() };
39//!     ProtobufResponse::ok(user)
40//! }
41//!
42//! async fn create_user(ApiRequest { body, format }: ApiRequest<CreateUserRequest>) -> ApiResponse<User> {
43//!     // body is decoded from either protobuf or JSON based on Content-Type
44//!     // response format matches the Accept header
45//!     ApiResponse::ok(format, user)
46//! }
47//! ```
48
49pub mod client;
50pub mod dual_format;
51pub mod error;
52pub mod extractors;
53#[cfg(feature = "metrics")]
54pub mod metrics;
55pub mod middleware;
56pub mod response;
57pub mod server;
58#[cfg(feature = "session")]
59pub mod session;
60pub mod tracing_init;
61
62/// Re-exports for convenient usage
63pub mod prelude {
64  pub use crate::{client::JetClient,
65                  dual_format::{AcceptFormat,
66                                ApiRequest,
67                                ApiResponse,
68                                ApiResult,
69                                DEBUG_FORMAT_HEADER,
70                                ResponseFormat,
71                                configure_debug_keys},
72                  error::{JetError,
73                          Result},
74                  extractors::ProtobufRequest,
75                  response::ProtobufResponse,
76                  server::JetServer};
77
78  // Re-export common axum types
79  pub use axum::{Router,
80                 extract::Path,
81                 routing::{delete,
82                           get,
83                           patch,
84                           post,
85                           put}};
86
87  // Re-export prost for protobuf
88  pub use prost::Message;
89
90  // Re-export serde for JSON support
91  pub use serde::{Deserialize,
92                  Serialize};
93
94  // Re-export async_trait
95  pub use async_trait::async_trait;
96
97  // Re-export CORS types for server configuration
98  pub use tower_http::cors::CorsLayer;
99
100  // Re-export tracing middleware
101  pub use crate::middleware::{SmartSpanMaker, smart_trace_layer};
102
103  // Re-export tracing initialization (always available)
104  pub use crate::tracing_init::{TracingConfig, TracingGuard, init_tracing};
105
106  // Re-export metrics types (when feature enabled)
107  #[cfg(feature = "metrics")]
108  pub use crate::metrics::{MetricsConfig, MetricsGuard, init_metrics, metrics_router, record_app_info};
109  #[cfg(feature = "metrics")]
110  pub use crate::middleware::HttpMetricsLayer;
111
112  // Re-export JWT types (when feature enabled)
113  #[cfg(feature = "jwt")]
114  pub use crate::middleware::{JwtAuthError, JwtAuthLayer, JwtConfig, JwtValidator};
115
116  // Re-export session types (when feature enabled)
117  #[cfg(feature = "session")]
118  pub use crate::session::{Session, SessionStore};
119}
120
121/// Content types used by AT-Jet
122pub mod content_types {
123  pub const APPLICATION_PROTOBUF: &str = "application/x-protobuf";
124  pub const APPLICATION_JSON: &str = "application/json";
125}