1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! # fetchttp
//!
//! A WHATWG Fetch API compliant HTTP client library for Rust.
//!
//! This library provides a familiar `fetch()` API that closely follows the
//! [WHATWG Fetch specification](https://fetch.spec.whatwg.org/), making it easy
//! for developers familiar with web APIs to use in Rust applications.
//!
//! ## Features
//!
//! - **Specification Compliant**: Implements the WHATWG Fetch API specification
//! - **Async/Await Support**: Built on Tokio for modern async Rust
//! - **Type Safety**: Leverages Rust's type system for safe HTTP operations
//! - **JSON Support**: Built-in JSON serialization/deserialization with serde
//! - **Flexible Bodies**: Support for text, bytes, and JSON request/response bodies
//! - **Header Management**: Complete header manipulation API
//! - **Request/Response Cloning**: Efficient cloning following the specification
//! - **Abort Signals**: Request cancellation support
//!
//! ## Quick Start
//!
//! ### Simple GET Request
//!
//! ```rust
//! use fetchttp::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let response = fetch("https://api.github.com/users/octocat", None).await?;
//!
//! if response.ok() {
//! let user: serde_json::Value = response.json().await?;
//! println!("User: {}", user["name"]);
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ### POST Request with JSON
//!
//! ```rust
//! use fetchttp::*;
//! use serde_json::json;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let data = json!({
//! "name": "John Doe",
//! "email": "john@example.com"
//! });
//!
//! let mut init = RequestInit::new();
//! init.method = Some("POST".to_string());
//! init.body = Some(ReadableStream::from_json(&data));
//!
//! let response = fetch("https://api.example.com/users", Some(init)).await?;
//!
//! if response.ok() {
//! println!("User created successfully!");
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ### Custom Headers
//!
//! ```rust
//! use fetchttp::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut headers = Headers::new();
//! headers.set("Authorization", "Bearer your-token")?;
//! headers.set("User-Agent", "MyApp/1.0")?;
//!
//! let mut init = RequestInit::new();
//! init.headers = Some(headers);
//!
//! let response = fetch("https://api.example.com/protected", Some(init)).await?;
//! let text = response.text().await?;
//!
//! println!("Response: {}", text);
//! Ok(())
//! }
//! ```
//!
//! ## API Overview
//!
//! The main entry point is the [`fetch`] function, which takes a URL and optional
//! [`RequestInit`] configuration. The function returns a [`Response`] that can be
//! consumed in various ways:
//!
//! - [`Response::text()`] - Get response as text
//! - [`Response::json()`] - Parse response as JSON
//! - [`Response::array_buffer()`] - Get response as bytes
//! - [`Response::blob()`] - Get response as blob (bytes)
//!
//! ## Error Handling
//!
//! The library uses a comprehensive error system with specific error types:
//!
//! - [`TypeError`] - Invalid arguments or operations
//! - [`NetworkError`] - Network-related failures
//! - [`AbortError`] - Request was aborted
//!
//! All errors implement the standard Rust error traits.
// Re-export all public types and functions
pub use ;
pub use ReadableStream;
pub use fetch;
pub use ;
pub use Headers;
pub use ;
pub use ;
// Re-export commonly used external types
pub use Bytes;
pub use ;