Skip to content

Instantly share code, notes, and snippets.

@mr-pascal
Last active June 9, 2022 18:02
Show Gist options
  • Save mr-pascal/53d19069d89ddfe14c218e6324553fd9 to your computer and use it in GitHub Desktop.
Save mr-pascal/53d19069d89ddfe14c218e6324553fd9 to your computer and use it in GitHub Desktop.
// - 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