To make an HTTP GET request in Rust, you can use the reqwest library. Add reqwest to your Cargo.toml file:
79 chars3 lines
Here's an example code to make a GET request to a URL:
main.rs187 chars9 linesIn the above code, we first import the get function from the reqwest::blocking module.
We then call the get function with the URL we want to GET. The get function returns a Result<Response, reqwest::Error>.
To get the response body as text, we call the text method on the response object. The text method returns a Result<String, reqwest::Error>.
We then print the response body to the console.
Note: the ? operator is used to propagate any errors that may occur when calling get or text.
gistlibby LogSnag