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
//! Generate type-safe, async HTTP clients from endpoint definitions.
//!
//! `beckon!` takes a client name and a list of endpoints and expands to a struct
//! with one async method per endpoint, a matching trait for mocking, and a typed
//! error enum.
//!
//! ```
//! use beckon::beckon;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Serialize, Deserialize)]
//! pub struct User {
//! pub id: u32,
//! pub name: String,
//! }
//!
//! #[derive(Serialize)]
//! pub struct UserPath {
//! pub id: u32,
//! }
//!
//! beckon!(
//! UserApi,
//! {
//! {
//! path: "/users",
//! method: GET,
//! res: Vec<User>,
//! },
//! {
//! path: "/users/{id}",
//! method: GET,
//! path_params: UserPath,
//! res: User,
//! }
//! }
//! );
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let client = UserApi::new(reqwest::Url::parse("https://api.example.com")?, Some(5000));
//! let _users = client.get_users().await?;
//! let _user = client.get_users_by_id(&UserPath { id: 1 }).await?;
//! # Ok(())
//! # }
//! # fn main() {}
//! ```
extern crate proc_macro;
use crateApiClientExpander;
use crateApiClientInput;
use parse_macro_input;
/// Generate a type-safe, async HTTP client from endpoint definitions.
///
/// See the [crate-level docs](crate) for the full endpoint grammar and features
/// (auth, retries, path/query params, headers, custom method names).