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
use Builder;
pub use ;
use Value;
use HashMap;
/// Structure representing HTTP configuration with base URL, headers, and client.
///
/// # Examples
///
/// ## 1. Using `.client()` manually
/// You create and pass a `reqwest::Client` manually. The headers inside the struct
/// are stored but not automatically applied to the client.
///
/// ```rust,no_run
/// use reqwest::{Client, header::{HeaderValue, USER_AGENT}};
/// use neto::components::data::Http;
///
/// fn main() {
/// let rt = tokio::runtime::Runtime::new().unwrap();
/// rt.block_on(async {
/// let headers = vec![
/// (USER_AGENT, HeaderValue::from_static("neto-http-test/1.0")),
/// ];
///
/// let http = Http::new()
/// .base_url("https://pokeapi.co/api/v2")
/// .headers(headers)
/// .client(Client::new()) // client created manually
/// .build()
/// .expect("Should build Http");
///
/// let response = http.get("/pokemon/ditto", Vec::new())
/// .await
/// .expect("GET request to PokeAPI failed");
///
/// assert!(response.status().is_success());
/// });
/// }
/// ```
///
/// ## 2. Using `.config()` to create the client internally
/// In this case, the `reqwest::Client` is not passed manually. After building the `Http`
/// struct, you call `.config()`, which creates the client internally and applies the
/// default headers stored in `Http.headers`.
///
/// ```rust,no_run
/// use reqwest::header::{HeaderValue, USER_AGENT};
/// use neto::components::data::Http;
///
/// fn main() {
/// let rt = tokio::runtime::Runtime::new().unwrap();
/// rt.block_on(async {
/// let headers = vec![
/// (USER_AGENT, HeaderValue::from_static("neto-http-test/1.0")),
/// ];
///
/// let mut http = Http::new()
/// .base_url("https://pokeapi.co/api/v2")
/// .headers(headers)
/// .build()
/// .expect("Should build Http");
///
/// http.config().expect("Failed to configure Http");
///
/// let response = http.get("/pokemon/ditto", Vec::new())
/// .await
/// .expect("GET request to PokeAPI failed");
///
/// assert!(response.status().is_success());
/// });
/// }
/// ```
///
/// # Key difference
///
/// - In the first example, the `reqwest::Client` is created externally and passed
/// manually to `Http`. The headers in the struct are not automatically applied to
/// the client.
///
/// - In the second example, the client is created internally by `Http::config()`,
/// which uses the stored headers to set default headers in the client.
///
/// Use `.config()` when you want the client to always include the stored headers,
/// such as authentication tokens, user-agent, etc., without creating the client
/// externally.
///
/// For simpler cases where the client is created separately, passing it manually
/// with `.client(Client::new())` may be sufficient.
pub type Header = ;
pub type Query = ;