1$ cargo version 2cargo 1.45.0 (744bd1fbb 2020-06-15) 3 4$ rustc --version 5rustc 1.45.0 (5c1f21c3b 2020-07-13)
HTTP クライアントの reqwest の crate を使う
reqwest
crates.io: Rust Package Registry
Cargo.toml には以下のように記載
Cargo.toml
1[dependencies] 2reqwest = { version = "0.10", features = ["json"] } 3tokio = { version = "0.2", features = ["full"] }
とりあえず GET して Body を取得してみる
1#[tokio::main] 2async fn main() -> Result<(), Box<dyn std::error::Error>> { 3 let res = reqwest::get("https://www.google.co.jp/").await?.text().await?; 4 println!("{:?}", res); 5 Ok(()) 6}
POST するときは以下のように:
1let client = reqwest::Client::new(); 2let res = client.post("http://httpbin.org/post") 3 .body("the exact body that is sent") 4 .send() 5 .await?;
reqwest_mock - Rust
reqwest の軽量クレート: ureq
ureq
[Rust] ureq - reqwest の軽量な代替クレート - Qiita
ここに掲載する記事はまだありません。