My Rust and actix-web web development learning application.
The database used in this application is the Oracle Corporation MySQL test database.
For each stage of the learning process, I document in a post which gets listed in the Related post(s) section below.
The code version for the above post has been tagged with v0.1.0. It can be cloned with:
git clone -b v0.1.0 https://github.com/behai-nguyen/rust_web_01.git
We write a Rust web application using a MySQL database. We use the already familiar crate sqlx for database works. The web framework we're using is crate actix-web. For Cross-Origin Resource Sharing (CORS) controls, we use crate actix-cors. For HTML template processing, we use crate tera, which implements Jinja2 template syntax.
The code version for the above post has been tagged with v0.2.0. It can be cloned with:
git clone -b v0.2.0 https://github.com/behai-nguyen/rust_web_01.git
We add request path extractor and MySQL database query calls to the official SayHi
middleware example. The middleware creates a text message, attaches it to the request via extension. This text message contains the detail of the first matched record, if any found, otherwise a no record found message. A resource endpoint service handler then extracts this message, and returns it as HTML to the client.
The code version for the above post has been tagged with v0.3.0. It can be cloned with:
git clone -b v0.3.0 https://github.com/behai-nguyen/rust_web_01.git
We've previously built an actix-web “application”, which has five (5) public POST
and GET
routes. We didn't implement any test at all. We're now retrofitting proper integration tests for these existing 5 (five) public routes.
The code version for the above post has been tagged with v0.4.0. It can be cloned with:
git clone -b v0.4.0 https://github.com/behai-nguyen/rust_web_01.git
I've been studying user authentication with the actix-web framework. It seems that a popular choice is to use crate actix-identity, which requires crate actix-session. To add these two (2) crates, the code of the existing application must be refactored a little. We first look at code refactoring and integration. Then we briefly discuss the official examples given in the documentation of the 2 (two) mentioned crates.
git clone -b v0.5.0 https://github.com/behai-nguyen/rust_web_01.git
We're implementing a login process for our actix-web learning application. We undertake some general updates to get ready to support login. We then implement a new /api/login route, which supports both application/x-www-form-urlencoded and application/json content types. In this post, we only implement deserialising the submitted request data, then echo some response. We also add a login page via route /ui/login.
git clone -b v0.6.0 https://github.com/behai-nguyen/rust_web_01.git
For our learning actix-web application, we are now adding two new features. ⓵ A simple email-password login with no session expiry.
⓶ A new middleware that manages
request authentication
using an
access token
“generated” by the login process. All
five existing routes
are now protected by this middleware: they can only be accessed if the
request has a valid
access token
.
With these two new features added, this application acts as both an
application server
and an
API-like server
or a service
.
git clone -b v0.7.0 https://github.com/behai-nguyen/rust_web_01.git
We are going to enable our actix-web learning application to run under HTTPS
. As a result, we need to do some minor refactoring to existing integration tests. We also move and rename an existing module for better code organisation.
git clone -b v0.8.0 https://github.com/behai-nguyen/rust_web_01.git
Continuing with our actix-web learning application, we will discuss proper AJAX calls to ensure reliable functionality of CORS and session cookies. This also addresses issue ❷ raised in a previous post.
git clone -b v0.9.0 https://github.com/behai-nguyen/rust_web_01.git
Continuing with our actix-web learning application, we implement global extractor error handlers for both application/json
and application/x-www-form-urlencoded
data. This enhances the robustness of the code. Subsequently, we refactor the login data extraction process to leverage the global extractor error handlers.
git clone -b v0.10.0 https://github.com/behai-nguyen/rust_web_01.git
In the sixth post of our actix-web learning application, we implemented a basic email-password login process with a placeholder for a token
. In this post, we will implement a comprehensive JSON Web Token (JWT)-based authentication system. We will utilise the jsonwebtoken crate, which we have previously studied.
git clone -b v0.11.0 https://github.com/behai-nguyen/rust_web_01.git
Currently, our actix-web learning application simply prints debug information to the console using the println!
macro. In this post, we will implement proper non-blocking daily logging to files. Daily logging
entails rotating to a new log file each day. Non-blocking
refers to having a dedicated thread for file writing operations. We will utilise the tracing, tracing-appender, and tracing-subscriber crates for our logging implementation.
git clone -b v0.12.0 https://github.com/behai-nguyen/rust_web_01.git
In the last post of our actix-web learning application, we identified two problems. First, there is an issue with calculating the UTC time offset on Ubuntu 22.10, as described in the section 💥 Issue with calculating UTC time offset on Ubuntu 22.10. Secondly, loggings from other crates that match the logging configuration are also written onto log files, as mentioned in the Concluding Remarks section. We should be able to configure what gets logged. We will address both of these issues in this post.
git clone -b v0.13.0 https://github.com/behai-nguyen/rust_web_01.git
In the tenth post of our actix-web learning application, we added an ad hoc middleware. In this post, with the assistance of the actix-web-lab crate, we will refactor this ad hoc middleware into a standalone async
function to enhance the overall code readability.
git clone -b v0.14.0 https://github.com/behai-nguyen/rust_web_01.git
Attempt to group log entries for each request within the markers Request [no session Id] entry
and Request [no session Id] exit
, or Request <Uuid V4> entry
and Request <Uuid V4> exit
.
💥 However, this revision of the code has not quite been able to achieve that.
I understand it should not be checked in. But this is only a development project, I checked it in for the shake of completeness.
MIT license and the GPL license.