-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathheader.rs
More file actions
42 lines (33 loc) · 1.16 KB
/
header.rs
File metadata and controls
42 lines (33 loc) · 1.16 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
use feignhttp::get;
use serde::Serialize;
// Using `#[header]` to specify header.
#[get("https://api.github.com/repos/dxx/feignhttp/commits")]
async fn commits(
#[header] accept: &str,
#[query] page: u32,
#[query] per_page: u32,
) -> feignhttp::Result<String> {}
// headers format: header-key1: header-value1; header-key2: header-value2; ...
#[get("https://httpbin.org/headers", headers = "key1: value1; key2: value2")]
async fn headers() -> feignhttp::Result<String> {}
#[derive(Serialize)]
pub struct Header {
pub accept: &'static str,
pub token: String,
}
#[get("https://httpbin.org/headers")]
async fn struct_headers(#[header] head: Header) -> feignhttp::Result<String> {}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let r = commits("application/vnd.github.v3+json", 1, 5).await?;
println!("commits result: {}\n", r);
let r = headers().await?;
println!("headers result: {}", r);
let header = Header {
accept: "content/json",
token: String::from("MDEwOlJlcG9zaXRvcnkzNDUyNTk4OTA="),
};
let r = struct_headers(header).await?;
println!("struct headers result: {}", r);
Ok(())
}