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::{Client, Result};
32//! use deboa_extras::http::sse::SseRequest;
33//! use futures_util::StreamExt;
34//!
35//! #[tokio::main]
36//! async fn main() -> Result<()> {
37//! let mut client = Client::default();
38//! let response = client
39//! .execute("https://sse.dev/test")
40//! .await?
41//! .into_event_stream();
42//!
43//! // Poll events, until the connection is closed
44//! // please note that this is a blocking call
45//! while let Some(event) = response.next().await {
46//! println!("event: {}", event);
47//! }
48//!
49//! println!("Connection closed");
50//! Ok(())
51//! }
52//! ```
53//!
54//! ### Using WebSockets
55//!
56//! ```compile_fail
57//! use deboa::{Client, Result};
58//! use deboa_extras::ws::{
59//! io::socket::DeboaWebSocket,
60//! protocol::{self},
61//! request::WebsocketRequestBuilder,
62//! response::IntoWebSocket,
63//! };
64//!
65//!
66//! #[tokio::main]
67//! async fn main() -> Result<()> {
68//! let mut client = Client::default();
69//! let websocket = WebsocketRequestBuilder::connect("wss://echo.websocket.org")
70//! .send_with(&mut client)
71//! .await?;
72//!
73//! // Send a message
74//! websocket.send_text("Hello, WebSocket!".into()).await?;
75//!
76//! // Receive messages
77//! while let Ok(Some(msg)) = websocket.read_message().await {
78//! match msg {
79//! protocol::Message::Text(text) => println!("Received text: {}", text),
80//! protocol::Message::Binary(data) => println!("Received binary data: {} bytes", data.len()),
81//! }
82//! }
83//! Ok(())
84//! }
85//! ```
86
87pub mod catcher;
88pub mod errors;
89pub mod http;
90
91#[cfg(feature = "compression")]
92//pub mod io;
93#[cfg(test)]
94mod tests;
95
96#[cfg(feature = "websockets")]
97pub mod ws;