deboa_extras/lib.rs
1//! # Deboa Extras
2//!
3//! `deboa-extras` is an extension crate for the `deboa` HTTP client that provides additional
4//! functionality and utilities for working with HTTP requests and responses.
5//!
6//! ## Features
7//!
8//! - **HTTP Utilities**: Additional HTTP-related functionality including:
9//! - Server-Sent Events (SSE) support
10//! - WebSocket client (when `websockets` feature is enabled)
11//! - Enhanced serialization/deserialization
12//! - **Compression**: Support for compressed request/response bodies (when `compression` feature is enabled)
13//! - **Error Handling**: Extended error types and utilities
14//! - **Catchers**: Pre-built error handlers for common scenarios
15//!
16//! ## Crate Features
17//!
18//! - `compression`: Enables compression support (gzip, deflate, brotli)
19//! - `websockets`: Enables WebSocket client functionality
20//! - `json`: Enables JSON serialization/deserialization
21//! - `msgpack`: Enables MessagePack serialization/deserialization
22//! - `xml`: Enables XML serialization/deserialization
23//! - `yaml`: Enables YAML serialization/deserialization
24//! - `flex`: Enables flexbuffers serialization/deserialization
25//!
26//! ## Examples
27//!
28//! ### Using Server-Sent Events (SSE)
29//!
30//! ```compile_fail
31//! use deboa_extras::http::sse::SseRequest;
32//! use futures_util::StreamExt;
33//!
34//! #[tokio::main]
35//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
36//! let mut client = deboa::Deboa::new();
37//! let response = client.execute("https://sse.dev/test").await?.into_event_stream();
38//!
39//! // Poll events, until the connection is closed
40//! // please note that this is a blocking call
41//! while let Some(event) = response.next().await {
42//! println!("event: {}", event);
43//! }
44//!
45//! println!("Connection closed");
46//! Ok(())
47//! }
48//! ```
49//!
50//! ### Using WebSockets
51//!
52//! ```compile_fail
53//! use deboa::{Deboa, Result, request::DeboaRequestBuilder};
54//! use deboa_extras::ws::{
55//! io::socket::DeboaWebSocket,
56//! protocol::{self},
57//! request::WebsocketRequestBuilder,
58//! response::IntoWebSocket,
59//! };
60//!
61//!
62//! #[tokio::main]
63//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
64//! let mut client = deboa::Deboa::new();
65//! let websocket = DeboaRequestBuilder::connect("wss://echo.websocket.org").send_with(&mut client).await?;
66//!
67//! // Send a message
68//! websocket.send_text("Hello, WebSocket!".into()).await?;
69//!
70//! // Receive messages
71//! while let Ok(Some(msg)) = websocket.read_message().await {
72//! match msg {
73//! protocol::Message::Text(text) => println!("Received text: {}", text),
74//! protocol::Message::Binary(data) => println!("Received binary data: {} bytes", data.len()),
75//! }
76//! }
77//! Ok(())
78//! }
79//! ```
80
81pub mod catcher;
82pub mod errors;
83pub mod http;
84
85#[cfg(feature = "compression")]
86pub mod io;
87#[cfg(test)]
88mod tests;
89
90#[cfg(feature = "websockets")]
91pub mod ws;