Skip to main content

http_request/request/request_builder/
struct.rs

1use super::*;
2
3/// Fluent builder for [`HttpRequest`].
4///
5/// Single-purpose, chainable. Each method returns `&mut Self` for fluent
6/// chaining; call [`RequestBuilder::build`] to obtain the final
7/// [`HttpRequest`].
8///
9/// # Examples
10///
11/// ```ignore
12/// use http_request::{RequestBuilder, Proxy};
13///
14/// // sync GET
15/// let mut req = RequestBuilder::new()
16///     .get("https://example.com/api")
17///     .header("Accept", "application/json")
18///     .timeout(5_000)
19///     .build();
20/// let _resp = req.send();
21///
22/// // async POST with JSON body
23/// let req = RequestBuilder::new()
24///     .post("https://example.com/api")
25///     .body_json(&serde_json::json!({"k": "v"}))
26///     .header("Content-Type", "application/json")
27///     .proxy(Proxy::https("127.0.0.1", 7890).auth("u", "p"))
28///     .build();
29/// let _resp = req.send_async().await;
30/// ```
31#[derive(Clone, Data, Debug, Default)]
32pub struct RequestBuilder {
33    #[get(pub(crate))]
34    #[get_mut(pub(crate))]
35    #[set(pub(crate))]
36    pub(crate) request: HttpRequest,
37}