Rust Programming Tutorial #38 - HTTP Get Request (reqwest Crate)

preview_player
Показать описание
Performing a HTTP GET Request is relatively straightforward in Rust. With the use of the reqwest crate, we are able to easily make HTTP requests. After watching this video you should be able to take advantage of HTTP technology and any APIs within your Rust programs.

In this video we look at two ways: the long way which provides you more flexibility when things don't go as expected, and a short way to quickly get a response back.

For your reference:

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

for people coming from 2022 or up reqwest now needs to have an async response, so you need to wrap the match in an async function or block and use the .await everything else should be fine
async fn foo() {
match reqwest::get("url").await {

}
}

if you want to use it directly on the main function you will have to get the tokio crate and derive async

existantperson
Автор

If you get an OpenSsl error while compiling change reqwest version to 0.9

echza
Автор

merci, beaucoup!
It very help me with learning rust after python
I try to do something like I did before on python

KOTOV_Alex
Автор

please make a video on reqwest, get and post request to api with json request and response and also manupulate and use the response like printing the json data like we do on python👍

henoknigatu
Автор

It doesn't work with reqwest 0.10.8. And it's wired that the codes copied from its documentation still didn't work.

TheHegwin
Автор

Does Rust not have any official http client?

WorstDeveloper
Автор

This no longer works with the current version of reqwest (2.0)

Skellingtor
Автор

I have the exact same code as you but keep getting "expected opaque type, found enum 'Result'" for mut response. Any idea why? I'm using reqwest 0.11 with features=[blocking, json]

SuperSmooochie
Автор

i was getting errors with this using reqwest 0.11. but i just changed the get function call to use reqwest::blocking. so instead of reqwest::get, just reqwest::blocking::get

tott
Автор

Why did they have to name it like that?

Mal-nfsp
Автор

i guess u should update this course, cuz all that not working

kamalkamals
Автор

This no longer works and the reqwest documentation seems out of date (how unusual)

mbartelsm
Автор

So the first part from the video does work, only StatusCode::OK needs to be used instead of 'Ok' with a small k...

fn main() {
// .expect("Couldn't make request")
// .text().expect("Couldnt not read response text!");

// println!("Response Text: {}", response_text);

Ok(mut response) => {
// Check if 200 OK
// The following part had an error
// You have to use 'OK' status code instead of 'Ok'
if response.status() == reqwest::StatusCode::OK {
match response.text() {
text {}", text),
Err(_)=> println!("Could not read response text!")
}

println!("Response was 200 OK.")
} else {
println!("Response was not 200 OK.")
}
}
Err(_) => println!("Could not make the request!")
}
}

crowncrow
Автор

I am trying to parse a string to a url with reqwest so I can pass it into a function dong a get request but I cannot figure out how to do that for the life of me

blazefirer
Автор

This tutorial does not work anymore... Tested first part.

alexmattheis