Sending HTTP Requests in Rust Applications 🦀 Rust Tutorial for Developers

preview_player
Показать описание
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.

Please follow me on these other social channels!

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
Рекомендации по теме
Комментарии
Автор

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.

ihgnmah
Автор

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

jmeumeu
Автор

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.

Aras
Автор

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

firstname-lastname
Автор

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?

farzadmf
Автор

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

xEvD
Автор

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

symshark
Автор

best rust tutos i've ever seen really

raph
Автор

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

hectorrios
Автор

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

RichardWalterLanda
Автор

This was a great tutorial - thank you!

dancostello
Автор

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.

DESCARTINPHILLIPLANCEB
Автор

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

xieen
Автор

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.

LexComments
Автор

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

CrapE_DM