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.
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
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
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.
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?
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! 🙂
@@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 😆)
@@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! 🦀🙂
@@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 🙂
@@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. 🙂
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.
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.
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.
Thank you!! 🙂 I'm glad you are discovering new tools! Mockoon is pretty helpful, right?
@@TrevorSullivan Yeah, its UX and DX are awesome.
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
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
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.
Thanks for this comment. Great to compare the two approaches.
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?
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! 🙂
@@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 😆)
@@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! 🦀🙂
@@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 🙂
@@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. 🙂
Your Rust videos are simply the best from the best, thank you!
Thanks. The additional crates you provided (especially mackoon) were very helpful.
best rust tutos i've ever seen really
That's very kind of you, thank you
but what is your vs code theme? i like the colors@@TrevorSullivan
@@raph384 it's the outrun theme by samrapdev
This tutorial came just in time. I wasn't familiar with Mockoon but I will be using it going forward to test scripts, thanks!
It's a great tool! 🙂 Rust on!! 🦀
Great video, thank you! Very clear and easy to follow, which is what we need more of when trying to learn Rust.
top! thnaks yu mate for what yu are doing. I think yu deserve much more attention of rust community! wish yu a good luck
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. 🦀🦀
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.
Hello! I installed libssl-dev and pkg-config with the apt package manager!
@@TrevorSullivanThank you for your response sir.
can you do a example of stream post and handle chunked json response?
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.
This was a great tutorial - thank you!
absolute legend
Why are you using ok() before all of your unwrap()s? Result has its own unwrap().
Yeah I must not have realized that earlier on. These days I have a better understanding of working with Result.