Sending HTTP Requests in Rust Applications 🦀 Rust Tutorial for Developers

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

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

  • @jmeumeu
    @jmeumeu ปีที่แล้ว +13

    One thing to keep in mind, is that even if the response is Ok(....), it does not mean that you have a 200 status code. So you probably want to check that response.status() is equal to reqwest::StatusCode::OK

    • @dooterino
      @dooterino 8 หลายเดือนก่อน +5

      response.status().is_success() would probably be a better route, it returns true for all values 200-299 which may be leveraged by an API for alternate success indicators

  • @ihgnmah
    @ihgnmah ปีที่แล้ว +11

    One of my favorite things about your videos is that you introduce us to various related tools. I didn't know about Mockoon and was having trouble setting up a proxy to avoid repeatedly hitting a production server. Thank you for sharing your knowledge with us.

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

      Thank you!! 🙂 I'm glad you are discovering new tools! Mockoon is pretty helpful, right?

    • @ihgnmah
      @ihgnmah ปีที่แล้ว

      @@TrevorSullivan Yeah, its UX and DX are awesome.

  • @Aras14
    @Aras14 ปีที่แล้ว +8

    A better way to do the check for error/ok is to do a match statement:
    match http_result {
    Ok(res) => {
    //Handling the response
    },
    Err(err) => {
    //Handling the error
    }
    }
    That way you avoid using unwrap so much, which in my opinion looks better, is easily readable and helps reduce panics.
    Edit: It also might be a little more performant.
    Edit2: A good place to use unwrap here is on the client builder, since your program can't work without it. If it fails it shouldn't run.

    • @foofighterdaz
      @foofighterdaz 11 หลายเดือนก่อน +1

      Thanks for this comment. Great to compare the two approaches.

  • @firstname-lastname
    @firstname-lastname หลายเดือนก่อน

    Your Rust videos are simply the best from the best, thank you!

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

    Thank you for the video, and all the videos honestly; I LOVE how you walk through the steps, not skipping any. Very nice job
    One question: you said you're running Rust programs on you Linux box (and I see VSCode is ssh-ing); does it mean that you're running mockoon remotely as well?

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

      Thanks so much for your kind comment!!
      Mockoon is running locally on my Windows 11 system. That's why I had to use it's mDNS name to connect to it remotely from the Rust code on the Linux VM. I hope this makes sense! Great question!
      By the way, I have another video series on LXD, which is what I use to launch Linux virtual machines for self-hosting and development purposes. You might be interested in that! 🙂

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

      @@TrevorSullivan will definitely check out the video. I personally use SSH port forwarding for these kinds of use cases. Don't know how to set up mDNS (honestly, had to Google it because didn't have any idea what it is 😆)

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

      @@farzadmf mDNS is just an easy way to resolve hostnames on a small network. It uses multicast, so you don't have to set up a dedicated DNS server. It's convenient, but has some limitations.
      You shouldn't need to use SSH forwarding since the VSCode remote extension will handle the SSH connection for you. Maybe I'm missing some details in your setup though.
      Rust on! 🦀🙂

    • @farzadmf
      @farzadmf ปีที่แล้ว

      @@TrevorSullivan Rust on indeed 😆
      As for SSH port-forwarding, my use case is maybe the other way around: a client on my local machine needs to access a server running on my remote SSH server; that's where I use port forwarding to accomplish that
      TBH, I've been what I call a "Rust watcher" for a long time, but your tutorials are so well done that encourage me to actually do something with Rust 😉
      One personal suggestion: it would be nice to start "putting things into practice" and create some project-based series; I'd personally love that/those 🙂

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

      @@farzadmf oh that makes sense! Using SSH as a transport security layer is excellent for accessing remote services!
      Thank you for your comment about my videos! I needed a push myself as well, since I'm not accustomed to working with low-level languages. Rust has really bridged the gap though, and I'm excited to learn about it!
      Project based videos are a great idea as well! I'll eventually get to something like that, where we "assemble all the pieces" and make a useful application. At the moment, I'm trying to take small bites before I dive too far into a whole app. 🙂

  • @xE92vD
    @xE92vD 11 หลายเดือนก่อน

    Thanks. The additional crates you provided (especially mackoon) were very helpful.

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

    This tutorial came just in time. I wasn't familiar with Mockoon but I will be using it going forward to test scripts, thanks!

    • @TrevorSullivan
      @TrevorSullivan  ปีที่แล้ว

      It's a great tool! 🙂 Rust on!! 🦀

  • @hectorrios1432
    @hectorrios1432 7 หลายเดือนก่อน

    Great video, thank you! Very clear and easy to follow, which is what we need more of when trying to learn Rust.

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

    best rust tutos i've ever seen really

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

      That's very kind of you, thank you

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

      but what is your vs code theme? i like the colors@@TrevorSullivan

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

      @@raph384 it's the outrun theme by samrapdev

  • @RichardWalterLanda
    @RichardWalterLanda 5 หลายเดือนก่อน

    top! thnaks yu mate for what yu are doing. I think yu deserve much more attention of rust community! wish yu a good luck

    • @TrevorSullivan
      @TrevorSullivan  5 หลายเดือนก่อน

      Thank you, Richard! I appreciate you being part of the community! I'm glad that you're learning from these videos. That's why I produce them. 🦀🦀

  • @DESCARTINPHILLIPLANCEB
    @DESCARTINPHILLIPLANCEB 10 หลายเดือนก่อน

    Hi Trevor, thank you for providing this tutorial. By the way, may I ask you a question? How did you fix that TLS error of OpenSSL and pkgconf? Thank you.

    • @TrevorSullivan
      @TrevorSullivan  10 หลายเดือนก่อน +1

      Hello! I installed libssl-dev and pkg-config with the apt package manager!

    • @DESCARTINPHILLIPLANCEB
      @DESCARTINPHILLIPLANCEB 10 หลายเดือนก่อน

      @@TrevorSullivanThank you for your response sir.

  • @xieen7976
    @xieen7976 7 หลายเดือนก่อน

    can you do a example of stream post and handle chunked json response?

  • @dancostello2
    @dancostello2 7 หลายเดือนก่อน

    This was a great tutorial - thank you!

  • @LexComments
    @LexComments ปีที่แล้ว

    Why not using a proper HTTP mock library instead of Mockoon? In any case, you want to have your tests automated to make sure there are no breaking changes in the future. I don't see how this can be achieved with Mockoon.

  • @alexbrun6863
    @alexbrun6863 10 หลายเดือนก่อน

    absolute legend

  • @CrapE_DM
    @CrapE_DM 2 หลายเดือนก่อน

    Why are you using ok() before all of your unwrap()s? Result has its own unwrap().

    • @TrevorSullivan
      @TrevorSullivan  2 หลายเดือนก่อน

      Yeah I must not have realized that earlier on. These days I have a better understanding of working with Result.