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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
//! # reqwest → OxiHTTP Migration Guide
//!
//! This module documents how to migrate from [`reqwest`](https://crates.io/crates/reqwest)
//! to OxiHTTP. OxiHTTP is a pure-Rust HTTP stack (no C/C++ dependencies) designed as a
//! drop-in replacement for most common reqwest usage patterns.
//!
//! ## Basic client setup
//!
//! **reqwest:**
//! ```rust,ignore
//! let client = reqwest::Client::new();
//! ```
//!
//! **OxiHTTP:**
//! ```rust,no_run
//! use oxihttp::Client;
//! let client = Client::builder().build().expect("client build");
//! ```
//!
//! ## GET request
//!
//! **reqwest:**
//! ```rust,ignore
//! let resp = client.get("https://httpbin.org/get").send().await?;
//! let body = resp.text().await?;
//! ```
//!
//! **OxiHTTP:**
//! ```rust,no_run
//! # async fn run() -> oxihttp::Result<()> {
//! # let client = oxihttp::Client::builder().build()?;
//! let resp = client.get("https://httpbin.org/get")?.send().await?;
//! let body = resp.body_text().await?;
//! # Ok(()) }
//! ```
//!
//! ## POST with JSON
//!
//! **reqwest:**
//! ```rust,ignore
//! #[derive(serde::Serialize)] struct Payload { name: String }
//! let resp = client.post(url).json(&Payload { name: "Alice".into() }).send().await?;
//! ```
//!
//! **OxiHTTP:**
//! ```rust,ignore
//! # use serde::Serialize;
//! # #[derive(Serialize)] struct Payload { name: String }
//! # async fn run() -> oxihttp::Result<()> {
//! # let client = oxihttp::Client::builder().build()?;
//! let resp = client.post("https://example.com/api")?
//! .json(&Payload { name: "Alice".into() })?
//! .send().await?;
//! # Ok(()) }
//! ```
//!
//! Note: in OxiHTTP, `json()` returns `Result<RequestBuilder, Error>` because it
//! serializes immediately. Use `?` to propagate errors.
//!
//! ## Custom headers
//!
//! **reqwest:**
//! ```rust,ignore
//! let resp = client.get(url).header("X-API-Key", "secret").send().await?;
//! ```
//!
//! **OxiHTTP:**
//! ```rust,no_run
//! # async fn run() -> oxihttp::Result<()> {
//! # let client = oxihttp::Client::builder().build()?;
//! let resp = client.get("https://api.example.com/data")?
//! .header("X-API-Key", "secret")?
//! .send().await?;
//! # Ok(()) }
//! ```
//!
//! Note: `header()` also returns `Result<RequestBuilder, Error>` because it validates
//! the header name/value immediately. Use `?` to propagate errors.
//!
//! ## Timeouts
//!
//! **reqwest:**
//! ```rust,ignore
//! use std::time::Duration;
//! let client = reqwest::Client::builder().timeout(Duration::from_secs(10)).build()?;
//! ```
//!
//! **OxiHTTP:**
//! ```rust,no_run
//! # use oxihttp::Result;
//! # fn example() -> Result<()> {
//! use std::time::Duration;
//! use oxihttp::Client;
//! let client = Client::builder()
//! .connect_timeout(Duration::from_secs(5))
//! .read_timeout(Duration::from_secs(10))
//! .build()?;
//! # Ok(()) }
//! ```
//!
//! OxiHTTP separates connect timeout from read timeout for finer control.
//! Per-request timeout is set via `RequestBuilder::timeout()`.
//!
//! ## Per-request timeout
//!
//! **reqwest:**
//! ```rust,ignore
//! let resp = client.get(url).timeout(Duration::from_secs(5)).send().await?;
//! ```
//!
//! **OxiHTTP:**
//! ```rust,no_run
//! # use std::time::Duration;
//! # async fn run() -> oxihttp::Result<()> {
//! # let client = oxihttp::Client::builder().build()?;
//! let resp = client.get("https://example.com")?
//! .timeout(Duration::from_secs(5))
//! .send().await?;
//! # Ok(()) }
//! ```
//!
//! ## TLS / HTTPS
//!
//! **reqwest:**
//! ```rust,ignore
//! let client = reqwest::Client::builder()
//! .danger_accept_invalid_certs(true) // for testing
//! .build()?;
//! ```
//!
//! **OxiHTTP (tls feature):**
//! ```rust,ignore
//! # #[cfg(feature = "tls")]
//! # fn example() -> oxihttp::Result<()> {
//! use oxihttp::Client;
//! let client = Client::builder()
//! .with_tls() // use webpki-roots CA bundle
//! .with_danger_accept_invalid_certs() // for testing only
//! .build_https()?;
//! # Ok(()) }
//! ```
//!
//! Unlike reqwest, OxiHTTP requires you to opt-in to a CA bundle explicitly
//! via `with_tls()` (webpki-roots) or `with_trusted_cert_der()`.
//!
//! ## Redirects
//!
//! **reqwest:**
//! ```rust,ignore
//! let client = reqwest::Client::builder()
//! .redirect(reqwest::redirect::Policy::none())
//! .build()?;
//! ```
//!
//! **OxiHTTP:**
//! ```rust,no_run
//! # fn example() -> oxihttp::Result<()> {
//! use oxihttp::{Client, RedirectPolicy};
//! let client = Client::builder()
//! .redirect_policy(RedirectPolicy::None)
//! .build()?;
//! # Ok(()) }
//! ```
//!
//! OxiHTTP's `RedirectPolicy` variants:
//! - `RedirectPolicy::None` — never follow redirects
//! - `RedirectPolicy::Limited(n)` — follow at most `n` redirects (default: 10)
//! - `RedirectPolicy::All` — follow all redirects
//!
//! ## Retry policy
//!
//! reqwest does not include built-in retry. OxiHTTP provides `RetryPolicy`:
//!
//! ```rust,no_run
//! # fn example() -> oxihttp::Result<()> {
//! use oxihttp::{Client, RetryPolicy};
//! let client = Client::builder()
//! .retry_policy(RetryPolicy::default())
//! .build()?;
//! # Ok(()) }
//! ```
//!
//! ## Streaming response body
//!
//! **reqwest:**
//! ```rust,ignore
//! use futures_util::StreamExt;
//! let mut stream = resp.bytes_stream();
//! while let Some(chunk) = stream.next().await { let _data = chunk?; }
//! ```
//!
//! **OxiHTTP:**
//! ```rust,no_run
//! # use futures_util::StreamExt;
//! # async fn run() -> oxihttp::Result<()> {
//! # let client = oxihttp::Client::builder().build()?;
//! # let resp = client.get("http://example.com/large")?.send().await?;
//! let mut stream = resp.body_stream();
//! while let Some(chunk) = stream.next().await { let _data = chunk?; }
//! # Ok(()) }
//! ```
//!
//! ## Error handling
//!
//! **reqwest:**
//! ```rust,ignore
//! let resp = client.get(url).send().await?;
//! resp.error_for_status()?; // 4xx/5xx → Err
//! ```
//!
//! **OxiHTTP:**
//! ```rust,no_run
//! # async fn run() -> oxihttp::Result<()> {
//! # let client = oxihttp::Client::builder().build()?;
//! let resp = client.get("http://example.com")?.send().await?;
//! resp.error_for_status()?; // same API
//! # Ok(()) }
//! ```
//!
//! ## JSON response deserialization
//!
//! **reqwest:**
//! ```rust,ignore
//! #[derive(serde::Deserialize)] struct ApiResult { id: u64 }
//! let result: ApiResult = resp.json().await?;
//! ```
//!
//! **OxiHTTP:**
//! ```rust,ignore
//! # use serde::Deserialize;
//! # #[derive(Deserialize)] struct ApiResult { id: u64 }
//! # async fn run() -> oxihttp::Result<()> {
//! # let client = oxihttp::Client::builder().build()?;
//! # let resp = client.get("http://example.com/api")?.send().await?;
//! let result: ApiResult = resp.body_json().await?;
//! # Ok(()) }
//! ```
//!
//! ## Authentication helpers
//!
//! **reqwest:**
//! ```rust,ignore
//! let resp = client.get(url).bearer_auth("my-token").send().await?;
//! let resp = client.get(url).basic_auth("user", Some("pass")).send().await?;
//! ```
//!
//! **OxiHTTP:**
//! ```rust,no_run
//! # async fn run() -> oxihttp::Result<()> {
//! # let client = oxihttp::Client::builder().build()?;
//! let resp = client.get("https://api.example.com/data")?
//! .bearer_token("my-token")?
//! .send().await?;
//!
//! let resp2 = client.get("https://api.example.com/data")?
//! .basic_auth("user", Some("pass"))?
//! .send().await?;
//! # Ok(()) }
//! ```
//!
//! ## HTTP server
//!
//! reqwest does not provide server functionality. OxiHTTP includes a full HTTP server:
//!
//! ```rust,no_run
//! # #[cfg(feature = "server")]
//! # async fn run() -> oxihttp::Result<()> {
//! use oxihttp::{Router, Server};
//!
//! let router = Router::new()
//! .get("/hello", |_req| async {
//! oxihttp_server::response::text_response("Hello!")
//! })
//! .health("/health");
//!
//! Server::bind("127.0.0.1:3000")
//! .serve(router)
//! .await?;
//! # Ok(()) }
//! ```
//!
//! ## Middleware (client-side)
//!
//! reqwest does not have built-in middleware. OxiHTTP provides a `ClientMiddleware` trait:
//!
//! ```rust,no_run
//! # fn example() -> oxihttp::Result<()> {
//! use oxihttp_client::middleware::LoggingMiddleware;
//! use oxihttp::Client;
//!
//! let client = Client::builder()
//! .with_middleware(LoggingMiddleware::new("my-client"))
//! .build()?;
//! # Ok(()) }
//! ```
//!
//! ## Feature flags comparison
//!
//! | reqwest feature | OxiHTTP feature | Notes |
//! |---|---|---|
//! | `default-tls` | `tls` | Pure Rust, uses rustls + oxitls |
//! | `rustls-tls` | `tls` | Same, always rustls |
//! | `gzip`, `deflate` | `decompression` | Uses oxiarc-deflate |
//! | `json` | always included | serde_json always available |
//! | *(no server)* | `server` | HTTP/1.1 + HTTP/2 server |
//! | *(no ws)* | `websocket` | RFC 6455 WebSocket |
//! | *(no socks)* | `socks` | SOCKS5 proxy (feature-gated) |
//! | `stream` | always included | `BodyStream` is always available |
//! | `multipart` | always included | `MultipartBuilder` in `oxihttp-core` |
//! | `cookies` | always included | `CookieJar` in `oxihttp-core` |
//!
//! ## Crate organisation
//!
//! OxiHTTP is split into multiple crates under the `oxihttp` workspace:
//!
//! - `oxihttp` — this facade crate; the only one most users need
//! - `oxihttp-core` — shared types (`OxiHttpError`, `Body`, `Cookie`, etc.)
//! - `oxihttp-client` — HTTP client implementation
//! - `oxihttp-server` — HTTP server, router, and middleware
//!
//! If you need low-level access, you can depend on the sub-crates directly.
//! For most migrations from reqwest, depending only on `oxihttp` is sufficient.