Making requests to APIs
Our last destination in this chapter brings us away from the server in favor of the other party participating in internet communication: the client. We will use reqwest
, which is built around hyper
, to create HTTPS requests to web services and parse their data into nicely usable Rust structures. You can also use the content of this recipe to write integration tests for your own web services.
How to do it...
- Open the
Cargo.toml
file that has been generated for you - Under
[dependencies]
, if you didn't do so in the last recipe, add the following lines:
reqwest = "0.8.5" serde = "1.0.30" serde_derive = "1.0.30"
- If you want, you can go to
request
's (https://crates.io/crates/reqwest),serde
's (https://crates.io/crates/serde), andserde_derive
's (https://crates.io/crates/serde_derive) crates.io pages to check for the newest versions and use those ones instead - In the folder
src/bin
, create a file calledmaking_requests.rs
- Add the following code and run it with
cargo run --bin making_requests...