Skip to content

Commit 91784bd

Browse files
author
Fernando López Aguilar
committed
Initial commit to access data
1 parent 53d8e15 commit 91784bd

3 files changed

Lines changed: 71 additions & 6 deletions

File tree

.gitignore

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,5 @@ Cargo.lock
1313
# MSVC Windows builds of rustc generate these, which store debugging information
1414
*.pdb
1515

16-
# RustRover
17-
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
18-
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
19-
# and can be added to the global gitignore or merged into this file. For a more nuclear
20-
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
21-
#.idea/
16+
# IDE
17+
.vscode/

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "github_statistics"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
reqwest = { version = "0.12.8", features = ["json"] } # reqwest with JSON parsing support
8+
futures = "0.3.31" # for our async / await blocks
9+
tokio = { version = "1.40.0", features = ["full"] } # for our async runtime
10+
serde = { version = "1.0", features = ["derive"] }

src/main.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use std::collections::HashMap;
2+
3+
use reqwest::header;
4+
use reqwest::Error;
5+
use serde::Deserialize;
6+
7+
#[derive(Deserialize, Debug)]
8+
struct User {
9+
login: String,
10+
id: u32,
11+
}
12+
13+
14+
// tokio let's us use "async" on our main function
15+
#[tokio::main]
16+
async fn main() -> Result<(), Error> {
17+
let client = reqwest::Client::new();
18+
let url= "https://api.github.com/repos/telefonicaid/fiware-orion/stargazers";
19+
let request_url = format!(
20+
"https://api.github.com/repos/{owner}/{repo}/stargazers",
21+
owner = "rust-lang-nursery",
22+
repo = "rust-cookbook"
23+
);
24+
25+
let mut headers = header::HeaderMap::new();
26+
headers.insert(header::AUTHORIZATION, header::HeaderValue::from_static("Bearer <YOUR TOKEN HERE>"));
27+
headers.insert(header::ACCEPT, header::HeaderValue::from_static("application/vnd.github.v3+json"));
28+
headers.insert(header::USER_AGENT, header::HeaderValue::from_static("reqwest"));
29+
30+
// Set up the query parameters for the request
31+
let mut params = HashMap::new();
32+
params.insert("per_page", 100);
33+
params.insert("page", 1);
34+
35+
36+
let body = reqwest::get("https://www.rust-lang.org")
37+
.await?
38+
.text()
39+
.await?;
40+
41+
println!("body = {body:?}");
42+
43+
let response = client
44+
.get(url)
45+
.headers(headers)
46+
.query(&params)
47+
.send()
48+
.await?
49+
.text()
50+
.await;
51+
52+
// Handle the response
53+
println!("{:#?}", response);
54+
55+
//let users: Vec<User> = response.json().await;
56+
//println!("{:?}", users);
57+
Ok(())
58+
}
59+

0 commit comments

Comments
 (0)