Questions tagged [reqwest]

reqwest is a high-level Rust HTTP client library that aims to be convenient and capable.

Documentation is available at https://docs.rs/reqwest/latest/reqwest/

215 questions
56
votes
2 answers

How can I perform parallel asynchronous HTTP GET requests with reqwest?

The async example is useful, but being new to Rust and Tokio, I am struggling to work out how to do N requests at once, using URLs from a vector, and creating an iterator of the response HTML for each URL as a string. How could this be done?
user964375
  • 2,201
  • 3
  • 26
  • 27
52
votes
1 answer

could not find `blocking` in `reqwest`

I am trying to download a text file from a given URL using reqwest 0.10.0-alpha.2, which looks like an appropriate tool. I have this in my Cargo.toml file: [package] name = "..." version = "0.1.0" authors = ["Y*** "] edition =…
Yuchen
  • 30,852
  • 26
  • 164
  • 234
35
votes
2 answers

How do I set the request headers using Reqwest?

I need to make a GET request to a website with a cookie using the Reqwest library. I figured out how to send a GET request: let response = reqwest::get("http://example.com")?; How do I send the same request but adding some custom headers?
serge1peshcoff
  • 4,342
  • 11
  • 45
  • 76
24
votes
1 answer

How can an arbitrary json structure be deserialized with reqwest get in Rust?

I am totally new to rust and I am trying to find out how to I can doload an deserialize a arbitrary JSON structure from a URL endpoint. The respective example on the reqwest README goes like this: use std::collections::HashMap; #[tokio::main] async…
LongHike
  • 4,016
  • 4
  • 37
  • 76
16
votes
1 answer

Rust handling error response bodies with Reqwest

I'm using the reqwest (version 0.10.4) crate for the HTTP calls in my Rust application but can't find any examples of how to handle APIs calls that could return more than one possible response body, mainly for error handling. For instance, an API…
m_callens
  • 6,100
  • 8
  • 32
  • 54
15
votes
2 answers

the `?` operator can only be used in an async block that returns `Result` or `Option

I'm learning rust and trying to scrape a random site by sending some POST data, and I'm getting a bunch of errors like: error[E0277]: the `?` operator can only be used in an async block that returns `Result` or `Option` (or another type that…
MB.
  • 4,167
  • 8
  • 52
  • 79
13
votes
1 answer

How is Reqwest higher level than Hyper?

According to the docs on Hyper.rs, If you are looking for a convenient HTTP client, then you may wish to consider reqwest. If you are looking for a convenient HTTP server, then you may wish to consider warp. Both are built on top of this…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
12
votes
1 answer

cannot use the `?` operator in a function that returns `()`

I am very new to rust and I want to write a script to scrape a page and pull all the links from it with their titles. I have failed to even make the get request. :( fn main() { println!("Started!"); let body =…
Liam Seskis
  • 161
  • 1
  • 2
  • 10
12
votes
1 answer

Why does a lazy-static value claim to not implement a trait that it clearly implements?

With the following code (an attempt to make an HTTP request using the reqwest crate), the compiler says that my value SID_URI does not implement the trait PolyfillTryInto. What's going on here? reqwest::Url clearly implements the private trait…
Fredrick Brennan
  • 7,079
  • 2
  • 30
  • 61
11
votes
2 answers

`?` couldn't convert the error to `std::io::Error`

I am attempting to do a post using the reqwest library and following patters that I have found in various places online: let res = http_client.post(&url) .header("Content-Type", "application/x-www-form-urlencoded") …
Jim Reineri
  • 2,830
  • 3
  • 31
  • 32
10
votes
1 answer

How to get body of response with reqwest?

I'm trying to send a GET request to the Binance API. But I'm getting this output in my terminal instead of the data: Response { url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("api.binance.com")),…
user1445685
  • 793
  • 1
  • 11
  • 25
10
votes
3 answers

How to POST a file using reqwest?

The documentation for reqwest v0.9.18 shows the following example of posting a file: let file = fs::File::open("from_a_file.txt")?; let client = reqwest::Client::new(); let res = client.post("http://httpbin.org/post") .body(file) …
Eric
  • 11,392
  • 13
  • 57
  • 100
10
votes
1 answer

reqwest::Error { kind: Decode, source: Error("expected value", line: 1, column: 1) }'

i get the following error while creating this POST request. Im a newbie in RUST. Instead of serde_json::Value I have even tried HashMap still the same issue. if you could tell me if my headers are wrong or how do I trace if its…
STEEL
  • 8,955
  • 9
  • 67
  • 89
8
votes
1 answer

Is it possible to get both the text and the JSON of a response from reqwest

From the reqwest docs, you can get the deserialized json, or the body text from a request response. What I can't see is how to get them both. My requirement is that I want the decoded json for use in the code but want to print out the text for…
Qwertie
  • 5,784
  • 12
  • 45
  • 89
8
votes
2 answers

JSON Body in POST Using the Rust reqwest Crate

I'm trying to implement this curl call using the Rust crate reqwest: curl -u [USERNAME]:[PASSWORD] -H "Content-Type: application/json" -d @content.json [WEBSITE] The file content.json encodes a JSON object as the name suggests. My code looks like…
THLO
  • 133
  • 1
  • 1
  • 4
1
2 3
14 15