Expand description
Networking module for Horizon Lattice.
This crate provides networking capabilities for Horizon Lattice applications:
- HTTP Client: Full-featured HTTP client with async support
- WebSocket: Real-time bidirectional communication
- TCP/UDP Sockets: Low-level socket communication (planned)
§HTTP Client
The HTTP client provides a high-level API for making HTTP requests:
ⓘ
use horizon_lattice_net::http::HttpClient;
// Create a client
let client = HttpClient::new();
// Make a request
let response = client.get("https://api.example.com/data")
.header("Accept", "application/json")
.send()
.await?;
// Read the response
let data: MyData = response.json().await?;§Request Methods
The client supports all common HTTP methods:
get(url)- GET requestpost(url)- POST requestput(url)- PUT requestdelete(url)- DELETE requestpatch(url)- PATCH requesthead(url)- HEAD request
§Request Bodies
ⓘ
// JSON body
client.post("/api/users")
.json(&serde_json::json!({"name": "John"}))
.send()
.await?;
// Form data
let mut form = HashMap::new();
form.insert("username".to_string(), "john".to_string());
client.post("/login").form(form).send().await?;
// Multipart (file upload)
let form = MultipartForm::new()
.text("name", "John")
.file_bytes("avatar", file_bytes, "avatar.png", Some("image/png"));
client.post("/upload").multipart(form).await?;§Configuration
ⓘ
let client = HttpClient::builder()
.timeout(Duration::from_secs(60))
.user_agent("MyApp/1.0")
.no_cookies()
.build()?;§Signal-Based Async
For GUI integration, use AsyncHttpClient which emits signals:
ⓘ
use horizon_lattice_net::http::{AsyncHttpClient, RequestStatus};
let client = AsyncHttpClient::new();
// Connect to the completion signal
client.request_finished.connect(|status| {
match status {
RequestStatus::Success { id, status_code, .. } => {
println!("Request {:?} completed with status {}", id, status_code);
}
RequestStatus::Error { id, message } => {
println!("Request {:?} failed: {}", id, message);
}
RequestStatus::Cancelled { id } => {
println!("Request {:?} was cancelled", id);
}
}
});
// Start request (returns immediately)
let handle = client.get_async("https://api.example.com/data");
// Cancel if needed
handle.cancel();Re-exports§
pub use tls::AlpnProtocol;pub use tls::Certificate;pub use tls::Identity;pub use tls::TlsConfig;pub use tls::TlsVersion;pub use http::ApiAuth;pub use http::AsyncHttpClient;pub use http::Authentication;pub use http::DownloadEvent;pub use http::DownloadId;pub use http::DownloadManager;pub use http::DownloadState;pub use http::ErrorTransformer;pub use http::HttpClient;pub use http::HttpClientBuilder;pub use http::HttpMethod;pub use http::HttpRequest;pub use http::HttpRequestBuilder;pub use http::HttpResponse;pub use http::MultipartForm;pub use http::RateLimitInfo;pub use http::RateLimiter;pub use http::RequestBody;pub use http::RequestHandle;pub use http::RequestId;pub use http::RequestInterceptor;pub use http::RequestStatus;pub use http::ResponseBody;pub use http::ResponseInterceptor;pub use http::RestApiClient;pub use http::RestApiClientBuilder;pub use http::RestApiRequestBuilder;pub use http::RetryConfig;pub use http::TransferProgress;pub use http::UploadConfig;pub use http::UploadEvent;pub use http::UploadId;pub use http::UploadManager;pub use http::UploadState;pub use tcp::ConnectionId;pub use tcp::TcpClient;pub use tcp::TcpClientConfig;pub use tcp::TcpConnection;pub use tcp::TcpConnectionState;pub use tcp::TcpServer;pub use tcp::TcpServerConfig;pub use tcp::TcpServerState;pub use tcp::TcpSocketConfig;pub use udp::Datagram;pub use udp::MulticastConfig;pub use udp::UdpSocket;pub use udp::UdpSocketConfig;pub use udp::UdpSocketState;pub use websocket::CloseCode;pub use websocket::CloseReason;pub use websocket::ReconnectConfig;pub use websocket::WebSocketClient;pub use websocket::WebSocketConfig;pub use websocket::WebSocketState;pub use dns::DnsConfig;pub use dns::DnsLookupResult;pub use dns::DnsResolver;pub use dns::IpStrategy;pub use network_info::GatewayInfo;pub use network_info::InterfaceChange;pub use network_info::InterfaceEvent;pub use network_info::InterfaceType;pub use network_info::Ipv4Info;pub use network_info::Ipv6Info;pub use network_info::MacAddress;pub use network_info::NetworkInterface;pub use network_info::NetworkMonitor;pub use network_info::check_connectivity;pub use graphql::GraphQLClient;pub use graphql::GraphQLClientBuilder;pub use graphql::GraphQLError;pub use graphql::GraphQLRequest;pub use graphql::GraphQLResponse;pub use graphql::SubscriptionMessage;pub use graphql::SubscriptionStream;pub use grpc::GrpcChannel;pub use grpc::GrpcChannelBuilder;pub use grpc::GrpcMetadata;pub use grpc::GrpcStatus;pub use grpc::GrpcStatusCode;
Modules§
- dns
- DNS resolution module for Horizon Lattice.
- graphql
- GraphQL client for queries, mutations, and subscriptions.
- grpc
- gRPC client support.
- http
- HTTP client for Horizon Lattice.
- network_
info - Network information module for Horizon Lattice.
- tcp
- TCP client and server with signal-based event delivery.
- tls
- TLS/SSL configuration types for secure connections.
- udp
- UDP socket with signal-based event delivery.
- websocket
- WebSocket client with real-time bidirectional communication.
Enums§
- Network
Error - Network-specific errors.
Type Aliases§
- Result
- A specialized Result type for network operations.