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;
53pub mod middleware;
54pub mod response;
55pub mod server;
56
57/// Re-exports for convenient usage
58pub mod prelude {
59 pub use crate::{client::JetClient,
60 dual_format::{AcceptFormat,
61 ApiRequest,
62 ApiResponse,
63 ApiResult,
64 DEBUG_FORMAT_HEADER,
65 ResponseFormat,
66 configure_debug_keys},
67 error::{JetError,
68 Result},
69 extractors::ProtobufRequest,
70 response::ProtobufResponse,
71 server::JetServer};
72
73 // Re-export common axum types
74 pub use axum::{Router,
75 extract::Path,
76 routing::{delete,
77 get,
78 patch,
79 post,
80 put}};
81
82 // Re-export prost for protobuf
83 pub use prost::Message;
84
85 // Re-export serde for JSON support
86 pub use serde::{Deserialize,
87 Serialize};
88
89 // Re-export async_trait
90 pub use async_trait::async_trait;
91
92 // Re-export CORS types for server configuration
93 pub use tower_http::cors::CorsLayer;
94}
95
96/// Content types used by AT-Jet
97pub mod content_types {
98 pub const APPLICATION_PROTOBUF: &str = "application/x-protobuf";
99 pub const APPLICATION_JSON: &str = "application/json";
100}