Browse Source

Preuve de Concept

nas 1 year ago
commit
b14f4a4ea1
3 changed files with 65 additions and 0 deletions
  1. 9
    0
      Cargo.toml
  2. 30
    0
      README.md
  3. 26
    0
      src/main.rs

+ 9
- 0
Cargo.toml View File

@@ -0,0 +1,9 @@
1
+[package]
2
+name = "client"
3
+version = "0.0.1"
4
+edition = "2021"
5
+
6
+[dependencies]
7
+#oauth2 = { version = "4.3.0", default-features = false }
8
+reqwest = { version = "0.11", features = ["json"] }
9
+tokio = { version = "1", features = ["full"] }

+ 30
- 0
README.md View File

@@ -0,0 +1,30 @@
1
+# Redmine Client
2
+
3
+## Usage
4
+
5
+Mettre son token dans le fichier `src/main.rs`
6
+
7
+## Ressources
8
+
9
+### Rust
10
+
11
+#### Examples
12
+
13
+##### Rest API client
14
+
15
+- https://github.com/seanmonstar/reqwest/issues/275
16
+- https://github.com/seanmonstar/reqwest
17
+- https://blog.logrocket.com/best-rust-http-client/
18
+- https://docs.rs/oauth2/latest/oauth2/#importing-oauth2-selecting-an-http-client-interface
19
+- https://blog.logrocket.com/making-http-requests-rust-reqwest/
20
+- https://blog.logrocket.com/jwt-authentication-in-rust/
21
+- https://www.thorsten-hans.com/calling-http-apis-in-rust-with-reqwest/
22
+- https://dev.to/pintuch/rust-reqwest-examples-10ff
23
+
24
+#### Librairies
25
+
26
+- REST API Client :
27
+  - https://rust-lang-nursery.github.io/rust-cookbook/web/clients/apis.html
28
+  - https://auth0.com/blog/build-an-api-in-rust-with-jwt-authentication-using-actix-web/
29
+- REST API Server : https://github.com/spietika/restson-rust
30
+- Web Server : https://github.com/http-rs/tide

+ 26
- 0
src/main.rs View File

@@ -0,0 +1,26 @@
1
+use reqwest;
2
+use reqwest::header;
3
+use std::error::Error;
4
+
5
+#[tokio::main]
6
+async fn main() -> Result<(), Box<dyn Error>> {
7
+    let server = "https://redmine.cli.coop";//https://api.coinstats.app/public/v1/coins/dogecoin
8
+    let token = "[TOKEN]";
9
+    let target = "issues.json";
10
+    let option = "limit=2";
11
+    let mut h = header::HeaderMap::new();
12
+    h.insert("X-Redmine-API-Key", header::HeaderValue::from_static( token ));
13
+    
14
+    let client = reqwest::Client::builder()
15
+        .default_headers(h)
16
+        .build()?;
17
+
18
+    let doge = client
19
+        .get( format!("{}/{}?{}", server, target, option ) )
20
+        .send()
21
+        .await?
22
+        .text()
23
+        .await?;
24
+    println!("{:}", doge);
25
+    Ok(())
26
+}

Loading…
Cancel
Save