Skip to content

hduoc2003/rust-web-api-microservice-template

 
 

Repository files navigation

RUST API SERVER

Logo

License Continuous Integration

Introduction

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.

How To Run

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

Example

  • Multiple config locations
./cli -c ./config/*.toml -c deploy/local/custom.toml
cargo install bunyan
./cli -c ./config/*.toml -c deploy/local/custom.toml | bunyan

Configuration

Order of apply

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.

Environment Variable Examples

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
DB__PG__MAX_SIZE

Make sure to set these environment variables according to your needs before running the server.

GitHub Flow CI Configuration

  1. Set Docker Hub Secrets:

    • Go to repository Settings > Secrets.
    • Add DOCKER_USERNAME and DOCKERHUB_TOKEN.
  2. Enable Dependabot Alerts:

    • In repository Insights, enable "Dependabot alerts" and "Security & Analysis."

Checklist

Basic Functionalities

Ensure comprehension and implementation of concepts outlined in the book with attention to detail. Key considerations include:

  1. Incorporating descriptive comments to enhance code readability.
  2. Implementing tracing mechanisms for effective debugging.
  3. Writing comprehensive test cases to validate functionality.
    1. Using https://testcontainers.com for integration tests.
  4. Utilizing version control with Git for code management.
  5. Structuring code in a logical and maintainable manner.
  6. Containerizing the application using Docker for portability and scalability.

Advanced Functionalities

Demonstrate proficiency in advanced development practices including:

  1. CLI Interface.
    1. Embed Git Info, Config Tool.
  2. Load Configuration from a File.
  3. Multiple Implementations.
  4. Advanced Tracing.
  5. CI/CD.
    1. Migrate DB tool/image.
    2. Publish binary artifacts in Github.
    3. Push Docker images.
    4. Deploy Dependabot
  6. Docker Image Optimization.
  7. Load test using K6.
    1. Use Flamegraph for profiling.
    2. Better UI.
  8. Comprehensive DB query filter for list().
  9. Optimize release binary performance.
  10. Docs on how to use this repo, the design behind the scene.

Feel free to explore and expand upon these functionalities as needed for your project. Happy coding!

Load Testing and Profiling

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 92.7%
  • Makefile 2.4%
  • Dockerfile 2.2%
  • PLpgSQL 2.1%
  • JavaScript 0.6%