horizon_lattice_net/lib.rs
1//! Networking module for Horizon Lattice.
2//!
3//! This crate provides networking capabilities for Horizon Lattice applications:
4
5#![warn(missing_docs)]
6// Allow pre-existing clippy lints - these are intentional patterns or need future refactoring
7#![allow(clippy::manual_strip)]
8#![allow(clippy::new_ret_no_self)]
9#![allow(clippy::option_map_unit_fn)]
10#![allow(clippy::match_single_binding)]
11#![allow(clippy::large_enum_variant)]
12//!
13//! - **HTTP Client**: Full-featured HTTP client with async support
14//! - **WebSocket**: Real-time bidirectional communication
15//! - **TCP/UDP Sockets**: Low-level socket communication (planned)
16//!
17//! # HTTP Client
18//!
19//! The HTTP client provides a high-level API for making HTTP requests:
20//!
21//! ```ignore
22//! use horizon_lattice_net::http::HttpClient;
23//!
24//! // Create a client
25//! let client = HttpClient::new();
26//!
27//! // Make a request
28//! let response = client.get("https://api.example.com/data")
29//! .header("Accept", "application/json")
30//! .send()
31//! .await?;
32//!
33//! // Read the response
34//! let data: MyData = response.json().await?;
35//! ```
36//!
37//! ## Request Methods
38//!
39//! The client supports all common HTTP methods:
40//!
41//! - `get(url)` - GET request
42//! - `post(url)` - POST request
43//! - `put(url)` - PUT request
44//! - `delete(url)` - DELETE request
45//! - `patch(url)` - PATCH request
46//! - `head(url)` - HEAD request
47//!
48//! ## Request Bodies
49//!
50//! ```ignore
51//! // JSON body
52//! client.post("/api/users")
53//! .json(&serde_json::json!({"name": "John"}))
54//! .send()
55//! .await?;
56//!
57//! // Form data
58//! let mut form = HashMap::new();
59//! form.insert("username".to_string(), "john".to_string());
60//! client.post("/login").form(form).send().await?;
61//!
62//! // Multipart (file upload)
63//! let form = MultipartForm::new()
64//! .text("name", "John")
65//! .file_bytes("avatar", file_bytes, "avatar.png", Some("image/png"));
66//! client.post("/upload").multipart(form).await?;
67//! ```
68//!
69//! ## Configuration
70//!
71//! ```ignore
72//! let client = HttpClient::builder()
73//! .timeout(Duration::from_secs(60))
74//! .user_agent("MyApp/1.0")
75//! .no_cookies()
76//! .build()?;
77//! ```
78//!
79//! # Signal-Based Async
80//!
81//! For GUI integration, use `AsyncHttpClient` which emits signals:
82//!
83//! ```ignore
84//! use horizon_lattice_net::http::{AsyncHttpClient, RequestStatus};
85//!
86//! let client = AsyncHttpClient::new();
87//!
88//! // Connect to the completion signal
89//! client.request_finished.connect(|status| {
90//! match status {
91//! RequestStatus::Success { id, status_code, .. } => {
92//! println!("Request {:?} completed with status {}", id, status_code);
93//! }
94//! RequestStatus::Error { id, message } => {
95//! println!("Request {:?} failed: {}", id, message);
96//! }
97//! RequestStatus::Cancelled { id } => {
98//! println!("Request {:?} was cancelled", id);
99//! }
100//! }
101//! });
102//!
103//! // Start request (returns immediately)
104//! let handle = client.get_async("https://api.example.com/data");
105//!
106//! // Cancel if needed
107//! handle.cancel();
108//! ```
109
110pub mod dns;
111mod error;
112pub mod graphql;
113pub mod grpc;
114pub mod http;
115pub mod network_info;
116pub mod tcp;
117pub mod tls;
118pub mod udp;
119pub mod websocket;
120
121pub use error::{NetworkError, Result};
122
123// Re-export TLS types
124pub use tls::{AlpnProtocol, Certificate, Identity, TlsConfig, TlsVersion};
125
126// Re-export commonly used types at the crate root
127pub use http::{
128 ApiAuth, AsyncHttpClient, Authentication, DownloadEvent, DownloadId, DownloadManager,
129 DownloadState, ErrorTransformer, HttpClient, HttpClientBuilder, HttpMethod, HttpRequest,
130 HttpRequestBuilder, HttpResponse, MultipartForm, RateLimitInfo, RateLimiter, RequestBody,
131 RequestHandle, RequestId, RequestInterceptor, RequestStatus, ResponseBody, ResponseInterceptor,
132 RestApiClient, RestApiClientBuilder, RestApiRequestBuilder, RetryConfig, TransferProgress,
133 UploadConfig, UploadEvent, UploadId, UploadManager, UploadState,
134};
135
136pub use tcp::{
137 ConnectionId, TcpClient, TcpClientConfig, TcpConnection, TcpConnectionState, TcpServer,
138 TcpServerConfig, TcpServerState, TcpSocketConfig,
139};
140
141pub use udp::{Datagram, MulticastConfig, UdpSocket, UdpSocketConfig, UdpSocketState};
142
143pub use websocket::{
144 CloseCode, CloseReason, ReconnectConfig, WebSocketClient, WebSocketConfig, WebSocketState,
145};
146
147pub use dns::{DnsConfig, DnsLookupResult, DnsResolver, IpStrategy};
148
149pub use network_info::{
150 GatewayInfo, InterfaceChange, InterfaceEvent, InterfaceType, Ipv4Info, Ipv6Info, MacAddress,
151 NetworkInterface, NetworkMonitor, check_connectivity,
152};
153
154pub use graphql::{
155 GraphQLClient, GraphQLClientBuilder, GraphQLError, GraphQLRequest, GraphQLResponse,
156 SubscriptionMessage, SubscriptionStream,
157};
158
159pub use grpc::{GrpcChannel, GrpcChannelBuilder, GrpcMetadata, GrpcStatus, GrpcStatusCode};