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

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ธ.ค. 2024

ความคิดเห็น •

  • @existantperson8624
    @existantperson8624 2 ปีที่แล้ว +28

    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

    • @gaznador2749
      @gaznador2749 2 ปีที่แล้ว

      Thanks a lot

    • @alihusham1560
      @alihusham1560 2 ปีที่แล้ว

      how to call async fn ainside regualr fn?

  • @echza
    @echza 5 ปีที่แล้ว +12

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

    • @HermanWillems
      @HermanWillems 4 ปีที่แล้ว +1

      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

    • @wMwPlay
      @wMwPlay 3 ปีที่แล้ว

      or just # sudo apt install pkg-config libssl-dev

  • @tott688
    @tott688 3 ปีที่แล้ว

    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

  • @SuperSmooochie
    @SuperSmooochie 3 ปีที่แล้ว

    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]

  • @TheHegwin
    @TheHegwin 4 ปีที่แล้ว

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

  • @WorstDeveloper
    @WorstDeveloper 5 ปีที่แล้ว +2

    Does Rust not have any official http client?

    • @farhanyousaf5616
      @farhanyousaf5616 3 ปีที่แล้ว

      I believe they do now, but not quite prod ready I would imagine yet.

  • @Skellingtor
    @Skellingtor 4 ปีที่แล้ว +1

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

  • @joe0404
    @joe0404 5 ปีที่แล้ว +1

    Another great Rust video!

  • @henoknigatu7121
    @henoknigatu7121 8 หลายเดือนก่อน

    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👍

  • @Mal-nf2sp
    @Mal-nf2sp 2 ปีที่แล้ว

    Why did they have to name it like that?

  • @kamalkamals
    @kamalkamals 2 ปีที่แล้ว

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

  • @mbartelsm
    @mbartelsm 4 ปีที่แล้ว

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

  • @elmondo.
    @elmondo. 3 ปีที่แล้ว

    Thank for the tutorial

  • @blazefirer
    @blazefirer 5 ปีที่แล้ว +1

    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

    • @inx1819
      @inx1819 5 ปีที่แล้ว +1

      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())

  • @crowncrow133
    @crowncrow133 4 ปีที่แล้ว

    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!")
    }
    }

  • @KOTOV_Alex
    @KOTOV_Alex 2 ปีที่แล้ว

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

  • @robert3258
    @robert3258 5 ปีที่แล้ว

    very helpful, thanks!

  • @baxiry.
    @baxiry. 7 ปีที่แล้ว +1

    Thank you very much

  • @alexmattheis
    @alexmattheis 4 ปีที่แล้ว +2

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

    • @JackMCGamerAnimations
      @JackMCGamerAnimations 4 ปีที่แล้ว

      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..