This is a simple Actix-Web server written in Rust that logs information to a file when accessed. Additionally, it allows users to register their personal information via command-line arguments.
- Logging: The server logs information to a file based on the provided nickname when accessed.
- Command-Line Interface (CLI) for User Registration: Users can register their personal information (first name, last name, and nickname) using command-line arguments.
- HTTP Endpoint for Logging
- Timestamped Logging
- State Sharing Between Handlers
- Command-Line Arguments Extraction
Rust programming language installed. Install Rust
-
Actix-Web: Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust. It provides the foundation for handling HTTP requests, defining routes, and managing the application's state. I built the server around Actix-Web's components, such as
App
andHttpServer
. -
Clap: Clap is a simple-to-use, efficient, and full-featured library for parsing command-line arguments in Rust. It simplifies the process of defining and extracting values from the command line. I used Clap to define and parse command-line arguments for registering a person. The server uses Clap to extract values such as first name, last name, and nickname from the command line.
-
Chrono: Chrono date and time library for Rust. In this server, I used it to capture the current timestamp for logging purposes.
-
File I/O: Standard Rust libraries for file input/output are used for creating and writing to files. The server uses
std::fs::File
andstd::fs::write
to create a file and write log entries to it. The file is named based on the provided nickname (app_state.n_name), and the content includes information about who created the file and when.
- Clone project
git clone https://github.com/tosynthegeek/trademark-username-lol.git
cd trademark-username-lol
- Build and run the server
cargo run
Server will be accessible at localhost:3000
To register a person and trigger the logging functionality, use the following command:
cargo run -- -n [NICKNAME] register-person -f [FIRST_NAME] -l [LAST_NAME]
Replace [NICKNAME], [FIRST_NAME] and [LAST_NAME] with the desired values.
Example:
cargo run -- -n tosynthegeek register-person -f Tosin -l Ojedapo
Once the server is running, you can access the logging endpoint by visiting localhost:3000
in your browser
Contributions are welcome! Please feel free to open issues or submit pull requests.