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
//! # better-fetch
//!
//! Typed HTTP client layer on top of [reqwest](https://docs.rs/reqwest), inspired by
//! [@better-fetch/fetch](https://better-fetch.vercel.app/docs). This crate is not affiliated
//! with the upstream TypeScript project.
//!
//! ## Quick flow
//!
//! 1. Create a [`Client`] (or [`ClientBuilder`]) with a base URL.
//! 2. Start a request with [`Client::get`] / [`Client::post`] (flexible [`RequestBuilder`])
//! or [`Client::call`] (typed [`Endpoint`] routes).
//! 3. Configure path params, query, body, auth, retries on the builder.
//! 4. Execute with [`RequestBuilder::send`] (buffered [`Response`]),
//! [`RequestBuilder::send_stream`] (incremental [`StreamingResponse`]),
//! [`send_json`](RequestBuilder::send_json), or [`EndpointRequestBuilder::send_json`](EndpointRequestBuilder::send_json).
//!
//! ## Buffered vs streaming
//!
//! - **`send` / `send_json`** — full body in memory; hooks and retry predicates can read the body.
//! - **`send_stream`** — `bytes_stream()` from reqwest; use [`StreamingResponse::collect`] to buffer when needed.
//! See the [`streaming`] module for limits (hooks, custom retry predicates, Tower backend).
//!
//! Use [`.get()`](Client::get) when you want string paths and a typed JSON response (`send_json::<T>()`).
//! Use [`Client::call`] when method, path, params, query, and response are bound to an [`Endpoint`] type.
//!
//! ## Cargo features
//!
//! The client always uses [reqwest](https://docs.rs/reqwest) as the default HTTP backend.
//! Enable crate features to turn on reqwest capabilities and optional APIs.
//!
//! | Feature | Description |
//! |---------|-------------|
//! | `json` (default) | JSON bodies, `send_json`, custom [`JsonParserFn`] |
//! | `rustls-tls` (default) | TLS via rustls (enable `native-tls` instead, not both) |
//! | `native-tls` | TLS via the platform stack (do not combine with `rustls-tls`) |
//! | `multipart` | [`RequestBuilder::multipart`] |
//! | `tower` | Tower transport stack via [`ClientBuilder::transport_stack`] (implies `rustls-tls`) |
//! | `schema` | [`SchemaRegistry`] route metadata |
//! | `openapi` | OpenAPI 3.0 export from schema registry |
//! | `validate` | Garde validation on JSON responses |
//! | `blocking`, `cookies` | Passed through to reqwest |
//! | `macros` | `#[derive(EndpointParamsDerive)]`, `#[derive(EndpointQueryDerive)]` proc-macros |
//!
//! See the [repository README](https://github.com/sebasxsala/better-fetch-rs) for full examples.
//!
//! ## Example (`.get()` — flexible path, typed response)
//!
//! ```no_run
//! # use better_fetch::{Client, Result};
//! # use serde::Deserialize;
//! # #[derive(Debug, Deserialize)]
//! # #[serde(rename_all = "camelCase")]
//! # struct Todo { user_id: u64, id: u64, title: String, completed: bool }
//! # #[tokio::main]
//! # async fn main() -> Result<()> {
//! let client = Client::new("https://jsonplaceholder.typicode.com")?;
//!
//! // send() returns Response for any status; json() fails on non-2xx
//! let todo: Todo = client
//! .get("/todos/:id")
//! .param("id", 1)
//! .send()
//! .await?
//! .json()
//! .await?;
//!
//! // Or in one step:
//! let todo: Todo = client.get("/todos/:id").param("id", 1).send_json().await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Example (typed endpoint — method, path, params, response)
//!
//! ```no_run
//! # use better_fetch::{Client, Endpoint, Result, define_params};
//! # use http::Method;
//! # use serde::Deserialize;
//! define_params!(GetTodoParams for "/todos/:id" { id: u64 });
//!
//! struct GetTodo;
//! impl Endpoint for GetTodo {
//! const METHOD: Method = Method::GET;
//! const PATH: &'static str = "/todos/:id";
//! type Response = Todo;
//! type Params = GetTodoParams;
//! type Query = ();
//! }
//!
//! # #[derive(Deserialize)]
//! # struct Todo { id: u64, title: String }
//! # #[tokio::main]
//! # async fn main() -> Result<()> {
//! let client = Client::new("https://jsonplaceholder.typicode.com")?;
//! let todo = client
//! .call::<GetTodo>()
//! .params(GetTodoParams { id: 1 })
//! .send_json()
//! .await?;
//! # Ok(())
//! # }
//! ```
pub use ;
pub use ;
pub use CancellationToken;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use LoggerPlugin;
pub use RequestBuilder;
/// Re-export of [reqwest multipart](https://docs.rs/reqwest/latest/reqwest/multipart/) types (feature `multipart`).
pub use multipart;
pub use Response;
pub use ;
pub use ;
pub use QueryValue;
pub use ;
pub use ;
pub use ;
/// Result alias using [`Error`].
pub type Result<T> = Result;