-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathjson.rs
More file actions
59 lines (48 loc) · 1.27 KB
/
json.rs
File metadata and controls
59 lines (48 loc) · 1.27 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
53
54
55
56
57
58
59
#![allow(dead_code)]
#![allow(unused_imports)]
use feignhttp::{get, post};
use serde::{Deserialize, Serialize};
// Deserialize: Specifies deserialization.
#[derive(Debug, Deserialize)]
struct IssueItem {
pub id: u32,
pub number: u32,
pub title: String,
pub url: String,
pub repository_url: String,
pub state: String,
pub body: Option<String>,
}
#[cfg(feature = "json")]
const GITHUB_URL: &str = "https://api.github.com";
#[cfg(feature = "json")]
#[get(url = GITHUB_URL, path = "/repos/{owner}/{repo}/issues")]
async fn issues(
#[path] owner: &str,
#[path] repo: &str,
page: u32,
per_page: u32,
) -> feignhttp::Result<Vec<IssueItem>> {}
#[derive(Debug, Serialize)]
struct User {
id: i32,
name: String,
}
#[cfg(feature = "json")]
#[post(url = "https://httpbin.org/anything")]
async fn post_user(#[body] user: User) -> feignhttp::Result<String> {}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "json")]
{
let r = issues("octocat", "hello-world", 1, 2).await?;
println!("issues: {:#?}", r);
let user = User {
id: 1,
name: "jack".to_string(),
};
let r = post_user(user).await?;
println!("{}", r);
}
Ok(())
}