Hey there, welcome back to my blog! 👋
If you’re learning Rust for the very first time I want to introduce you to 5 simple yet practical projects that will help you later in real-world projects. I wrote another article with 5 ideas, this is one step up on the learning ladder.
The concepts I’m presenting below are pretty basic; every Rust developer should know them.
Below you’ll find the 5 project ideas, the posts (tweets) where I’m explaining step-by-step how you can build these projects and a link to the corresponding GitHub repo!
Project Idea 5: Simple Get Request
// Detect dark theme
var iframe = document.getElementById(‘tweet-1759158982546014265-247’);
if (document.body.className.includes(‘dark-theme’)) {
iframe.src = “https://platform.twitter.com/embed/Tweet.html?id=1759158982546014265&theme=dark”
}
In the above post, I’m explaining how to make a GET request using the reqwest
crate in Rust, handle the response, and print the status code, headers, and body of the response. Additionally, in the code, you’ll find the error_chain
crate for error handling.
Check it on GitHub.
Project Idea 4: Asynchronous GET Request
// Detect dark theme
var iframe = document.getElementById(‘tweet-1759864645605589238-100’);
if (document.body.className.includes(‘dark-theme’)) {
iframe.src = “https://platform.twitter.com/embed/Tweet.html?id=1759864645605589238&theme=dark”
}
If you try this code for yourself you’ll learn how to:
-
Make an asynchronous GET request using the
reqwest
crate in Rust -
Handle the response asynchronously using
async
andawait
-
Print the status code, headers, and body of the response
Check it on GitHub.
Project Idea 3: Making API Calls
// Detect dark theme
var iframe = document.getElementById(‘tweet-1760230631508734230-896’);
if (document.body.className.includes(‘dark-theme’)) {
iframe.src = “https://platform.twitter.com/embed/Tweet.html?id=1760230631508734230&theme=dark”
}
If you completed the above projects I suggest you now work with API calls. In the project I’m presenting here you’ll be able to learn how to:
-
Make an HTTP GET request to an API endpoint using the
reqwest
crate -
Handle the response asynchronously using
async
andawait
-
Deserialize the JSON response into Rust structs using
serde
-
Additionally, you can use the
User-Agent
header in the request to identify the client making the request
Check it on GitHub.
Project Idea 2: Very Basic Authentication
// Detect dark theme
var iframe = document.getElementById(‘tweet-1760626620233347501-305’);
if (document.body.className.includes(‘dark-theme’)) {
iframe.src = “https://platform.twitter.com/embed/Tweet.html?id=1760626620233347501&theme=dark”
}
Overall, after finishing this project you’ll be able to: make a synchronous GET request to a URL using the reqwest
crate and also add basic authentication to the request and handle the response.
Check it on GitHub.
Project Idea 1: Download an Image
// Detect dark theme
var iframe = document.getElementById(‘tweet-1761030147052802531-13’);
if (document.body.className.includes(‘dark-theme’)) {
iframe.src = “https://platform.twitter.com/embed/Tweet.html?id=1761030147052802531&theme=dark”
}
This idea about this project is about downloading an image from a specified URL (in this case, the Rust logo image from the Rust website) and saving it to a temporary directory on the local file system.
Here’s an overview of what the program does:
-
It creates a temporary directory using
tempfile::Builder
. -
It specifies the URL of the image to be downloaded (
https://rust-lang.org/logos/rust-logo-512x512.png
). -
It sends an asynchronous GET request to the specified URL using the
reqwest
crate. -
It extracts the file name from the response URL and creates a file with that name in the temporary directory.
-
It reads the content of the response body as text asynchronously.
-
It copies the content of the response body, represented as bytes, to the file created in the temporary directory.
-
It prints information about the downloaded file, such as the file name and the location where it is stored in the temporary directory.
-
It returns
Ok(())
, indicating that the program executed successfully.
Check it on GitHub.
Notes
I’m new to Rust and I hope these small projects will help you get better and improve your skills. Check here part 1 of Rust project ideas for beginners and if you need more resources I’d also like to suggest Akhil Sharma‘s YouTube Channel.
👋 Hello, I’m Eleftheria, Community Manager, developer, public speaker, and content creator.
🥰 If you liked this article, consider sharing it.