Skip to content

Instantly share code, notes, and snippets.

@elmariachi111
Created May 21, 2021 21:20
Show Gist options
  • Save elmariachi111/2f83c3704db8ff9b3fd2c0b295cfb1b7 to your computer and use it in GitHub Desktop.
Save elmariachi111/2f83c3704db8ff9b3fd2c0b295cfb1b7 to your computer and use it in GitHub Desktop.
Rust hyper http client sample
[package]
name = "testssl"
version = "0.1.0"
authors = ["Stefan Adolf <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.11.3", features = ["json"] }
hyper = { version = "0.14", features = ["full"] }
hyper-tls = { version = "0.5.0" }
tokio = { version = "1", features = ["full"] }
use hyper::Client;
use hyper::{Body, Method, Request};
use hyper_tls::HttpsConnector;
use reqwest::header::USER_AGENT;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let https = HttpsConnector::new();
let client = Client::builder().build::<_, hyper::Body>(https);
let req = Request::builder()
.method(Method::GET)
.uri("https://api.github.com/repos/golemfactory/yagna/releases/latest")
.header(USER_AGENT, "My Rust Program 1.0")
.body(Body::empty())?;
let resp = client.request(req).await?;
println!("{:#?}", resp);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment