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
Extra for Ubuntu: Change to 0.9 and open commandline and type: *sudo apt install libssl-dev* (to install the needed files to compile this dependency) And for the request i used this test url: jsonplaceholder.typicode.com/todos/1
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
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]
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👍
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
Do you get an error like it expects a str but it got a String instead? Just parse it as a str, like this Assume blah is the String url reqwest::get(blah.as_str())
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() { // let response_text = reqwest::get("www.google.com") // .expect("Couldn't make request") // .text().expect("Couldnt not read response text!"); // println!("Response Text: {}", response_text); match reqwest::get("www.google.com") { 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() { Ok(text)=>println!(" Response 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!") } }
Well first, the version he is using for reqwest is old (since he made this video in 2018). And, reqwest probably changed some functions up so you have to read the reqwest docs to see how you can solve the problem..
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
Thanks a lot
how to call async fn ainside regualr fn?
If you get an OpenSsl error while compiling change reqwest version to 0.9
Extra for Ubuntu: Change to 0.9 and open commandline and type: *sudo apt install libssl-dev* (to install the needed files to compile this dependency)
And for the request i used this test url: jsonplaceholder.typicode.com/todos/1
or just # sudo apt install pkg-config libssl-dev
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
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]
It doesn't work with reqwest 0.10.8. And it's wired that the codes copied from its documentation still didn't work.
Does Rust not have any official http client?
I believe they do now, but not quite prod ready I would imagine yet.
This no longer works with the current version of reqwest (2.0)
Another great Rust video!
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👍
Why did they have to name it like that?
i guess u should update this course, cuz all that not working
This no longer works and the reqwest documentation seems out of date (how unusual)
Thank for the tutorial
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
Do you get an error like it expects a str but it got a String instead?
Just parse it as a str, like this
Assume blah is the String url
reqwest::get(blah.as_str())
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() {
// let response_text = reqwest::get("www.google.com")
// .expect("Couldn't make request")
// .text().expect("Couldnt not read response text!");
// println!("Response Text: {}", response_text);
match reqwest::get("www.google.com") {
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() {
Ok(text)=>println!("
Response 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!")
}
}
merci, beaucoup!
It very help me with learning rust after python
I try to do something like I did before on python
very helpful, thanks!
Thank you very much
This tutorial does not work anymore... Tested first part.
Well first, the version he is using for reqwest is old (since he made this video in 2018). And, reqwest probably changed some functions up so you have to read the reqwest docs to see how you can solve the problem..