We can make web requests in just a few steps:
- Open a Terminal to create a new project using cargo new web-requests. Use VS Code to open the project directory.
- First, let's edit Cargo.toml to add the dependencies we are going to use later:
[dependencies]surf = "1.0"reqwest = "0.9"serde = "1"serde_json = "1"runtime = "0.3.0-alpha.6"
- Let's start importing these external dependencies and setting up some data structs in src/main.rs:
#[macro_use]extern crate serde_json;use surf::Exception;use serde::Serialize;#[derive(Serialize)]struct MyGetParams { a: u64, b: String,}
- surf (https://github.com/rustasync/surf) is a recent crate developed fully async. Let's create a test function to see it in action. First, we create the client ...