elif_http/
lib.rs

1//! # elif-http
2//!
3//! HTTP server core for the elif.rs LLM-friendly web framework.
4//!
5//! This crate provides a NestJS-like HTTP server experience with:
6//! - Clean, intuitive API that abstracts Axum complexity
7//! - Integration with the elif-core DI container
8//! - Built-in middleware pipeline
9//! - Graceful shutdown handling
10//! - Health check endpoints
11//! - Framework-native routing system
12
13// Core modules
14pub mod bootstrap;
15pub mod config;
16pub mod controller;
17pub mod errors;
18pub mod foundation;
19pub mod handlers;
20pub mod logging;
21pub mod middleware;
22pub mod request;
23pub mod response;
24pub mod routing;
25pub mod server;
26pub mod testing;
27pub mod websocket;
28
29// Feature-gated modules
30#[cfg(feature = "auth")]
31pub mod auth;
32
33// Main server API - NestJS-like experience
34pub use bootstrap::{AppBootstrap, AppBootstrapper, BootstrapError, BootstrapResult, create_bootstrapper};
35pub use config::HttpConfig;
36pub use errors::{HttpError, HttpResult, VersionedError, VersionedErrorBuilder, VersionedErrorExt};
37pub use server::Server;
38
39// Re-export foundation types
40pub use foundation::{BoxFuture, GenericHandler, IntoElifResponse, RequestExtractor};
41
42// Re-export routing types
43pub use routing::{
44    header_versioned_router,
45    path_versioned_router,
46    versioned_router,
47    ElifRouter,
48    GroupBuilder,
49    HttpMethod,
50    ParamError,
51    ParamType,
52    PathParams,
53    RouteBuilder,
54    RouteGroup,
55    RouteInfo,
56    RouteParam as RoutingRouteParam,
57    RouteRegistry,
58    VersionedRouteBuilder,
59    // Versioned routing
60    VersionedRouter,
61};
62
63// Re-export request/response types
64pub use request::{ElifMethod, ElifPath, ElifQuery, ElifRequest, ElifState};
65pub use response::{
66    ElifHeaderMap, ElifHeaderName, ElifHeaderValue, ElifResponse, ElifStatusCode, ResponseBody,
67};
68
69// Re-export JSON handling
70pub use response::{ApiResponse, ElifJson, JsonError, JsonResponse, ValidationErrors};
71
72// Re-export middleware types - V2 system is now the default
73pub use middleware::{
74    body_limit::{BodyLimitConfig, BodyLimitInfo, BodyLimitMiddleware},
75    enhanced_logging::{
76        EnhancedLoggingMiddleware, LoggingConfig as MiddlewareLoggingConfig, RequestContext,
77    },
78    // Core middleware
79    error_handler::{
80        error_handler, error_handler_with_config, ErrorHandlerConfig, ErrorHandlerMiddleware,
81    },
82    logging::LoggingMiddleware as LegacyLoggingMiddleware,
83    timeout::{apply_timeout, TimeoutConfig, TimeoutInfo, TimeoutMiddleware},
84    timing::{format_duration, RequestStartTime, TimingMiddleware},
85    tracing::{RequestMetadata, TracingConfig, TracingMiddleware},
86    // V2 Middleware System (default)
87    v2::{
88        LoggingMiddleware, Middleware, MiddlewarePipelineV2 as MiddlewarePipeline, Next,
89        SimpleAuthMiddleware,
90    },
91    // Versioning middleware
92    versioning::{
93        default_versioning_middleware, versioning_layer, versioning_middleware, ApiVersion,
94        RequestVersionExt, VersionInfo, VersionStrategy, VersioningConfig, VersioningLayer,
95        VersioningMiddleware, VersioningService,
96    },
97};
98
99// Re-export authentication types (if auth feature is enabled)
100#[cfg(feature = "auth")]
101pub use auth::{AuthMiddleware, RequestAuthExt};
102
103// Re-export logging types
104pub use logging::{init_logging, log_shutdown_info, log_startup_info, structured, LoggingConfig};
105// Re-export specific LoggingContext from context module
106pub use logging::context::LoggingContext;
107
108// Re-export controller types
109pub use controller::{
110    BaseController, Controller, ControllerRoute, ElifController, RouteParam as ControllerRouteParam,
111};
112// Re-export from specific modules to avoid conflicts
113pub use controller::pagination::{PaginationMeta, QueryParams};
114
115// Re-export derive macros (if derive feature is enabled)
116#[cfg(feature = "derive")]
117pub use elif_http_derive::{
118    body, controller, delete, get, group, head, middleware, options, param, patch, post, put,
119    resource, routes,
120};
121
122// Re-export handler types
123pub use handlers::{elif_handler, ElifHandler};
124
125// Re-export testing utilities (for development and testing)
126pub use testing::{
127    create_test_container, get_test_port, test_error_handler, test_handler, test_http_config,
128    test_json_handler, test_socket_addr, ErrorAssertions, HttpAssertions, TestContainerBuilder,
129    TestQuery, TestServerBuilder, TestUser,
130};
131
132// Re-export WebSocket types
133pub use websocket::{
134    ConnectionEvent,
135    ConnectionId,
136    ConnectionRegistry,
137    ConnectionState,
138    MessageType,
139    SimpleWebSocketHandler,
140    WebSocketConfig,
141    // Connection management
142    WebSocketConnection,
143    WebSocketError,
144    WebSocketHandler,
145    // Core types
146    WebSocketMessage,
147    WebSocketResult,
148    // Server and handler
149    WebSocketServer,
150    WebSocketUpgrade,
151};
152
153// Legacy compatibility re-exports
154pub use errors::HttpError as ElifError;
155pub use response::ElifJson as Json;
156
157// Framework-native types - Use these instead of raw Axum types
158// Note: Use Router from routing module, not axum::Router
159// Note: Use ElifJson instead of axum::Json
160// Note: Use ElifResponse instead of axum::Response
161// Note: HTTP types are available through response/request modules when needed