Sending HTTP Requests in Rust Applications 🦀 Rust Tutorial for Developers

Ғылым және технология

There are several different crates available for Rust, that allow you to craft and send HTTP requests to remote servers. The crate we'll be looking at, in this video, is called "reqwest." Reqwest is built on top of another low-level HTTP client crate called "Hyper." You can use both a synchronous or asynchronous approach to handling HTTP requests. To keep things easy to understand in this video, we'll stick with synchronous requests!
You can customize your HTTP headers, endpoint, port number, and payload (body) in your requests, and process any similar data fields from the response. You can use this technique to interact with any HTTP API that's available, or perform data scraping against various websites.
🤯 Rust Programming Playlist 🦀 • Rust Programming Tutor...
📖 Reqwest Docs 📦➡️ docs.rs/reqwest
Visual Studio Code ➡️ code.visualstudio.com
Rust Website ➡️ rust-lang.org
Rustup Installer ➡️ rustup.rs
Rust Docs ➡️ doc.rust-lang.org/book
Please follow me on these other social channels!
➡️ trevorsullivan.net
➡️ github.com/pcgeek86
➡️ / pcgeek86
➡️ / trevorsullivan
➡️ / trevorsoftware
➡️ tiktok.com/pcgeek86
All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names,trademarks and brands does not imply endorsement.
#rustlang #rust #rustdev #opensource #software #linux #devops #programming #rusty #dev #coding #codinglife #code #coder #ubuntu #ubuntulinux #appdev #developer

Пікірлер: 34

  • @ihgnmah
    @ihgnmah8 ай бұрын

    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

    8 ай бұрын

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

  • @ihgnmah

    @ihgnmah

    8 ай бұрын

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

  • @jmeumeu
    @jmeumeu9 ай бұрын

    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

    3 ай бұрын

    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

  • @Aras14
    @Aras148 ай бұрын

    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

    6 ай бұрын

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

  • @xE92vD
    @xE92vD6 ай бұрын

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

  • @hectorrios1432
    @hectorrios14322 ай бұрын

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

  • @RichardWalterLanda
    @RichardWalterLandaАй бұрын

    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

    Ай бұрын

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

  • @dancostello2
    @dancostello22 ай бұрын

    This was a great tutorial - thank you!

  • @symshark
    @symshark9 ай бұрын

    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

    9 ай бұрын

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

  • @alexbrun6863
    @alexbrun68635 ай бұрын

    absolute legend

  • @raph384
    @raph3848 ай бұрын

    best rust tutos i've ever seen really

  • @TrevorSullivan

    @TrevorSullivan

    8 ай бұрын

    That's very kind of you, thank you

  • @raph384

    @raph384

    8 ай бұрын

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

  • @TrevorSullivan

    @TrevorSullivan

    8 ай бұрын

    @@raph384 it's the outrun theme by samrapdev

  • @farzadmf
    @farzadmf9 ай бұрын

    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

    9 ай бұрын

    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

    9 ай бұрын

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

    9 ай бұрын

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

    9 ай бұрын

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

    9 ай бұрын

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

  • @xieen7976
    @xieen79762 ай бұрын

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

  • @user-xd8pl8vw8g
    @user-xd8pl8vw8g5 ай бұрын

    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

    5 ай бұрын

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

  • @user-xd8pl8vw8g

    @user-xd8pl8vw8g

    5 ай бұрын

    @@TrevorSullivanThank you for your response sir.

  • @user-jf7wh4zw5y
    @user-jf7wh4zw5y8 ай бұрын

    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.

Келесі