Welcome to the Rust API Server! This server provides a simple REST interface for your applications. This README will guide you through setting up and running the server, as well as configuring its various options.
Automated Builds:
Builds are automatically generated for each commit to the repository in the main
branch and are subsequently pushed to Docker Hub.
Tags are applied using the commit SHA, branch name, and the latest tag if released on the main branch. You can find a list of available
tags here.
Release Binaries:
For every release, separate cli
binaries are built. These binaries can be downloaded
from here and are available for various operating
systems and architectures. You are welcome to use the automated binaries or build your own.
Contributions and PRs: If you submit a pull request, please note that images are not built by default. A maintainer will need to retag them for the build process to take place.
- Pull the docker image
docker pull thuan2172001/rust-server:latest
- Run the image
docker run -d -p 8000:8000 thuan2172001/rust-server:latest
To get started, execute the following command in your terminal:
./cli --help
This will display the available options for running the server:
Simple REST server
Usage: cli [OPTIONS] [COMMAND]
Commands:
config Print config
help Print this message or the help of the given subcommand(s)
Options:
-c, --config-path <CONFIG_PATH> Config file [default: config/default.toml]
-v, --version Print version
-h, --help Print help
- Multiple config locations
./cli -c ./config/*.toml -c deploy/local/custom.toml
- Pipe the output with bunyan
cargo install bunyan
./cli -c ./config/*.toml -c deploy/local/custom.toml | bunyan
Configuration is applied in the following order: config files -> environment variables -> command-line arguments.
If you use -c *.toml
to load config files, please be mindful of the order in which the files are applied.
The server can be configured using environment variables. Below is a table outlining the available configuration options:
Hierarchical child config via env, separated by using __
. Specify list values by using ,
separator
ENV | DEFAULT VALUE | NOTE |
---|---|---|
RUST_LOG > LOG__LEVEL | "INFO" | Log level |
SERVER__URL | ||
SERVER__PORT | ||
SERVICE_NAME | ||
EXPORTER_ENDPOINT | ||
DB__PG__URL | "localhost" | |
DB__PG__MAX_SIZE | 5432 | |
REDIS__HOST | "localhost" | |
REDIS__PORT | 6379 |
Make sure to set these environment variables according to your needs before running the server.
-
Set Docker Hub Secrets:
- Go to repository Settings > Secrets.
- Add
DOCKER_USERNAME
andDOCKERHUB_TOKEN
.
-
Enable Dependabot Alerts:
- In repository Insights, enable "Dependabot alerts" and "Security & Analysis".
Ensure comprehension and implementation of concepts outlined in the book with attention to detail. Key considerations include:
- Incorporating descriptive comments to enhance code readability.
- Implementing tracing mechanisms for effective debugging.
- Writing comprehensive test cases to validate functionality.
- Using https://testcontainers.com for integration tests.
- Utilizing version control with Git for code management.
- Structuring code in a logical and maintainable manner.
- Containerizing the application using Docker for portability and scalability.
Demonstrate proficiency in advanced development practices including:
- CLI Interface.
- Embed Git Info, Config Tool.
- Load Configuration from a File.
- Multiple Implementations.
- Advanced Tracing.
- CI/CD.
- Publish binary artifacts in Github.
- Push Docker images.
- Build pipeline on amd arch.
- Build pipeline on arm arch.
- Docker Image Optimization.
- Load test using K6.
- Use Flamegraph for profiling.
- Better UI.
- Comprehensive DB query filter for list().
- Optimize release binary performance.
- Docs on how to use this repo, the design behind the scene.
- Dependabot
- Update Rust.
- Update Docker image.
Feel free to explore and expand upon these functionalities as needed for your project. Happy coding!
For load testing and profiling your Rust API server, refer to the Load Testing and Profiling with K6 and Flamegraph guide. This document provides detailed instructions on using K6 and Flamegraph for load testing and profiling purposes.