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
use TokenStream;
/// Derive the `Api` trait
///
/// # Example
/// ```
/// use api_req_derive::Payload;
/// use serde::Serialize;
/// use reqwest::Method;
///
/// #[derive(Payload, Serialize)]
/// #[api_req(
/// path = "/api/v1/{id}", // format `id` from struct field
/// method = Method::GET,
/// headers = [("k1", "v1"), ("k2", "{x}")] // format `x` from struct field
/// )]
/// struct Test {
/// #[serde(skip_serializing)]
/// id: u32,
/// #[serde(skip_serializing)]
/// x: String,
/// }
/// ```
///
/// If `method` is set to POST, one should set `req` to `json` or `form` as needed manually.
///
/// The default derive code is `GET` method with `query` request.
/// Derive the `Api` trait
///
/// # Example
/// ```
/// use api_req_derive::ApiCaller;
/// use reqwest::header;
///
/// #[derive(ApiCaller)]
/// #[api_req(
/// base_url = "http://example.com",
/// default_headers = [("k1", "v1"), (header::ORIGIN, "v2")],
/// default_headers_env = [("k3", "API_KEY")],
/// default_headers_env_or_omit = [("k4", "BALABALA")],
/// )]
/// struct ExampleApi;
/// ```