AT-Jet
High-performance HTTP + Protobuf API framework for mobile services.
Not just a wrapper - AT-Jet is an opinionated, production-ready foundation for mobile API development. See Architecture Rationale for why this project exists.
Why AT-Jet?
Building mobile APIs with Protobuf over HTTP requires solving the same problems repeatedly:
- Content-type negotiation
- Request body size limits
- Consistent error handling
- Client library generation
- Team coding conventions
Without AT-Jet (30+ lines per handler):
async
With AT-Jet (5 lines):
async
Features
- HTTP/1.1 and HTTP/2 support via axum
- Protobuf request/response handling with automatic content negotiation
- Dual-format support - Protobuf for production, JSON for debugging (with key authorization)
- CDN-friendly design for global mobile users
- Middleware support for authentication, logging, compression
- Prometheus metrics (optional
metricsfeature) - HTTP request instrumentation and scrape endpoint - Smart tracing - automatic log-level filtering for health/metrics endpoints
- Tracing initialization - unified setup with optional Jaeger/OpenTelemetry (
tracing-otelfeature) - JWT authentication (optional
jwtfeature) - HMAC-based JWT middleware with Bearer token extraction - Session management (optional
sessionfeature) - in-memory session store with TTL and idle timeout - Graceful shutdown -
serve_with_shutdown()for clean Ctrl+C handling - Startup banner - pre-tracing service info output for k8s environments
- Type-safe routing with compile-time guarantees
- Efficient bandwidth - Protobuf is 60-70% smaller than JSON
- Schema evolution - Protobuf handles backward/forward compatibility
Quick Start
Add to your Cargo.toml:
[]
= "0.6"
= { = "1", = ["full"] }
= "0.13"
[]
= "0.13"
See Quick Start Guide for a complete 5-minute tutorial.
Server Example
use *;
async
async
async
async
Client Example
use *;
async
Dual-Format Support (Protobuf + JSON)
AT-Jet supports both Protobuf (production) and JSON (debugging) formats. JSON requires authorization via debug keys to prevent accidental use in production.
Why Require Authorization for JSON?
Protobuf provides schema evolution guarantees that JSON lacks:
- Field numbers enable backward/forward compatibility
- Unknown fields are preserved during deserialization
- Optional fields have well-defined defaults
If clients accidentally use JSON in production, they lose these guarantees and may break when the schema evolves. The debug key requirement ensures JSON is only used intentionally.
Configuring Debug Keys
use *;
async
Using Dual-Format Handlers
use *;
// Dual-format handler - accepts both Protobuf and JSON
async
Client Usage
# Protobuf request (production - no debug key needed)
# JSON request (debugging - requires valid debug key)
# JSON request without debug key → rejected with 415 Unsupported Media Type
Format Selection Rules
| Request Format | Response Format | Condition |
|---|---|---|
| Protobuf | Protobuf | Default (production) |
| JSON | JSON | Valid X-Debug-Format header |
| JSON | Error 415 | Missing/invalid debug key |
| Protobuf | JSON | Accept: application/json + valid debug key |
Architecture
Mobile Clients (iOS, Android, Web)
│
▼
CDN (Global)
│
▼
┌─────────────┐
│ AT-Jet │ ◄── HTTP + Protobuf
│ Server │
└─────────────┘
│
▼
┌─────────────┐
│ Backend │ ◄── ZUS-RS (internal RPC)
│ Services │
└─────────────┘
Why HTTP + Protobuf?
| Factor | JSON | Protobuf |
|---|---|---|
| Size | 100% | 30-40% (60-70% smaller) |
| Parse Speed | 100% | 10-20% (5-10x faster) |
| Schema Evolution | Manual | Built-in |
| Type Safety | Runtime | Compile-time |
Running Examples
# Start server
# In another terminal, run client
Optional: Prometheus Metrics
Enable the metrics feature for built-in Prometheus instrumentation:
[]
= { = "0.6", = ["metrics"] }
use *;
use Arc;
let guard = init_metrics.unwrap;
let server = new
.route
.route
.with_metrics // Scrape endpoint + HTTP metrics
.with_tracing;
This adds:
http_requests_totalcounter (method, endpoint, status)http_request_duration_secondshistogram (method, endpoint)http_active_requestsgauge (endpoint)- Prometheus scrape endpoint at the configured path
Optional: Tracing Initialization
Initialize tracing with optional Jaeger support:
[]
= { = "0.6", = ["tracing-otel"] }
use *;
let config = TracingConfig ;
let _guard = init_tracing; // Keep guard alive!
TracingConfig and init_tracing() are always available. Jaeger support requires the tracing-otel feature.
Optional: JWT Authentication
Enable JWT middleware for protected routes:
[]
= { = "0.6", = ["jwt"] }
use *;
let config = JwtConfig ;
let server = new
.route
.layer;
Optional: Session Management
In-memory session store with TTL and idle timeout:
[]
= { = "0.6", = ["session"] }
use *;
use HashMap;
let store = new; // 8h TTL, 15min idle
let token = store.create.await;
Documentation
- Quick Start - Get running in 5 minutes
- User Guide - Complete feature documentation
- Architecture Rationale - Why AT-Jet exists and design decisions
- API Docs - Generated API documentation
- CLAUDE.md - Development guidance and coding conventions
License
MIT OR Apache-2.0