Last active
June 9, 2022 18:02
-
-
Save mr-pascal/53d19069d89ddfe14c218e6324553fd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - Doing a GET request | |
let resp404 = client.get("https://httpbin.org/status/404") | |
.send() | |
.await?; | |
// - Matching the HTTP status code of the request | |
match resp404.status() { | |
// - "OK - 200" everything was good | |
reqwest::StatusCode::OK => { | |
println!("Success!"); | |
// ... | |
}, | |
// - "NOT_FOUND - 404" the resource wasn't found | |
reqwest::StatusCode::NOT_FOUND => { | |
println!("Got 404! Haven't found resource!"); | |
// Output: | |
/* | |
Got 404! Haven't found resource! | |
*/ | |
}, | |
// - Every other status code which doesn't match the above ones | |
_ => { | |
panic!("Okay... this shouldn't happen..."); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment