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