-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcustom_client.rs
More file actions
52 lines (43 loc) · 1.53 KB
/
Copy pathcustom_client.rs
File metadata and controls
52 lines (43 loc) · 1.53 KB
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
use feignhttp::{Client, ClientWrapper, FeignClientBuilder, feign};
#[feign(url = "https://api.github.com", headers = "user-agent: Feign HTTP")]
pub trait GitHub {
#[get("/users/{user}")]
async fn user(&self, #[path] user: &str) -> feignhttp::Result<String>;
#[get("/repos/dxx/feignhttp/commits")]
async fn commits(
&self,
#[header] accept: &str,
#[query] page: u32,
#[query] per_page: u32,
) -> feignhttp::Result<String>;
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client_wrapper;
#[cfg(feature = "reqwest-client")]
{
// You can use reqwest's custom configuration.
let client = reqwest::Client::builder().build()?;
client_wrapper = ClientWrapper::with_client(client)?;
}
#[cfg(feature = "reqwest-middleware-client")]
{
use reqwest_middleware::{ClientBuilder, reqwest};
let reqwest_client = reqwest::Client::builder().build()?;
let client = ClientBuilder::new(reqwest_client).build();
client_wrapper = ClientWrapper::with_client(client)?;
}
#[cfg(feature = "isahc-client")]
{
let client = isahc::HttpClient::builder().build()?;
client_wrapper = ClientWrapper::with_client(client)?;
}
let github = GitHubBuilder::build_with_client(client_wrapper)?;
let r = github.user("dxx").await?;
println!("{}", r);
let r = github
.commits("application/vnd.github.v3+json", 1, 1)
.await?;
println!("commits result: {}\n", r);
Ok(())
}