Rust API Server: A versatile template for building RESTful interfaces, designed for simplicity in setup and configuration using the Rust programming language.

Overview

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.

Deploy

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.

Docker

  1. Pull the docker image
docker pull thuan2172001/rust-server:latest
  1. Run the image
docker run -d -p 8000:8000 thuan2172001/rust-server:latest

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.

You might also like...
A C-like programming language that is similar to Rust's syntax. Toy programming language.
A C-like programming language that is similar to Rust's syntax. Toy programming language.

CRUST This is a hobby project to learn about compilers and language design. I've designed the language to be similar to C and Rust. Heavily inspired b

A high level DSL for Simplicity. This is a work in progress and is not yet ready for production use

A high level DSL for Simplicity. This is a work in progress and is not yet ready for production use. The language is designed to be simple and easy to use. It is inspired by rust syntax and is statically typed. The syntax will be extended in the future to support more features.

A web-based streaming service with improved privacy, performance, and simplicity.

Majiix Majiix is a web-based open-source streaming service. The backend that handles the core streaming logic is written in Rust and makes use of cutt

RustGPT is a ChatGPT UI built with Rust + HTMX: the power of Rust coupled with the simplicity of HTMX 💚

RustGPT 🦀✨ RustGPT.Blog.Post.mp4 Welcome to the RustGPT repository! Here, you'll find a web ChatGPT clone entirely crafted using Rust and HTMX, where

YAML(ish) - Terminal UI framework based on templates focused on simplicity
YAML(ish) - Terminal UI framework based on templates focused on simplicity

A YAML(ish) based terminal GUI framework for- and by Rust, focussed on making it quick and easy to create a functional UI for an app or game. Based on Crossterm and inspired by Kivy.

A Yocto setup and management tool that helps you keep your environment up-to-date and in-sync with your team
A Yocto setup and management tool that helps you keep your environment up-to-date and in-sync with your team

yb (Yocto Buddy) yb is designed to make it easy to setup and (perhaps more importantly) keep Yocto environments up-to-date and in-sync with your team.

Scriptable tool to read and write UEFI variables from EFI shell. View, save, edit and restore hidden UEFI (BIOS) Setup settings faster than with the OEM menu forms.
Scriptable tool to read and write UEFI variables from EFI shell. View, save, edit and restore hidden UEFI (BIOS) Setup settings faster than with the OEM menu forms.

UEFI Variable Tool (UVT) UEFI Variable Tool (UVT) is a command-line application that runs from the UEFI shell. It can be launched in seconds from any

ratlab is a programming platform designed loosely for hobbyist and masochist to analyse and design stuff and things that transform our world?
ratlab is a programming platform designed loosely for hobbyist and masochist to analyse and design stuff and things that transform our world?

ratlab A programming language developed by Quinn Horton and Jay Hunter. ratlab is a programming platform designed loosely for hobbyists and masochists

Tool to create web interfaces to command-line tools

webgate This command line utility allows you to: serve files and directories listed in a config file remotely run shell commands listed in a config fi

Comments
  • build(deps): bump opentelemetry-semantic-conventions from 0.13.0 to 0.14.0

    build(deps): bump opentelemetry-semantic-conventions from 0.13.0 to 0.14.0

    Bumps opentelemetry-semantic-conventions from 0.13.0 to 0.14.0.

    Release notes

    Sourced from opentelemetry-semantic-conventions's releases.

    v0.14.0

    Added

    • Adding a dynamic dispatch to Aggregator Selector #497
    • Add global::force_flush_tracer_provider #512
    • Add config max_attributes_per_event and max_attributes_per_link #521
    • Add dropped attribute counts to events and links #529

    Changed

    • Remove unnecessary clone in Key type #491
    • Remove #[must_use] from set_tracer_provider #501
    • Rename remaining usage of default_sampler to sampler #509
    • Use current span for SDK-less context propagation #510
    • Always export span batch when limit reached #519
    • Rename message events to events #530
    • Update resource merge behaviour #537
    • Ignore links with invalid context #538

    Removed

    • Remove remote span context #508
    • Remove metrics quantiles #525

    Fixed

    • Allow users to use custom export kind selector #526

    Performance

    • Improve simple span processor performance #502
    • Local span perf improvements #505
    • Reduce string allocations where possible #506
    Commits

    Dependabot compatibility score

    You can trigger a rebase of this PR by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • build(deps): bump opentelemetry_sdk from 0.21.2 to 0.22.0

    build(deps): bump opentelemetry_sdk from 0.21.2 to 0.22.0

    Bumps opentelemetry_sdk from 0.21.2 to 0.22.0.

    Release notes

    Sourced from opentelemetry_sdk's releases.

    v0.22.0

    API

    Added

    Changed

    Removed

    SDK

    Deprecated

    • XrayIdGenerator in the opentelemetry-sdk has been deprecated and moved to version 0.10.0 of the opentelemetry-aws crate.

    Added

    • #1410 Add experimental synchronous gauge

    • #1471 Configure batch log record processor via OTEL_BLRP_* environment variables and via OtlpLogPipeline::with_batch_config

    • #1503 Make the documentation for In-Memory exporters visible.

    • #1526 Performance Improvement : Creating Spans and LogRecords are now faster, by avoiding expensive cloning of Resource for every Span/LogRecord.

    Changed

    • Breaking #1313 #1350 Changes how Span links/events are stored to achieve performance gains. See below for details:

      Behavior Change: When enforcing max_links_per_span, max_events_per_span from SpanLimits, links/events are kept in the first-come order. The previous "eviction" based approach is no longer performed.

      Breaking Change Affecting Exporter authors:

      SpanData now stores links as SpanLinks instead of EvictedQueue where SpanLinks is a struct with a Vec of links and dropped_count.

      SpanData now stores events as SpanEvents instead of EvictedQueue where SpanEvents is a struct with a Vec of events and dropped_count.

    • Breaking Remove TextMapCompositePropagator #1373. Use TextMapCompositePropagator in opentelemetry API.

    ... (truncated)

    Commits

    Dependabot compatibility score

    You can trigger a rebase of this PR by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • build(deps): bump opentelemetry-otlp from 0.14.0 to 0.15.0

    build(deps): bump opentelemetry-otlp from 0.14.0 to 0.15.0

    Bumps opentelemetry-otlp from 0.14.0 to 0.15.0.

    Release notes

    Sourced from opentelemetry-otlp's releases.

    v0.15.0

    Added

    • More resource detectors #573

    Changed

    • Expose the Error type to allow users to set custom error handlers #551
    • Allow users to use different channels based on runtime in batch span processor #560
    • Move Unit into metrics module #564
    • Update trace flags to match spec #565

    Fixed

    • Fix debug loop, add notes for #[tokio::test] #552
    • TraceState cannot insert new key-value pairs #567
    Commits
    • d7ba1ea Prepare for v0.15.0 release (#572)
    • 6834b64 feat: add more resource detectors (#573)
    • efbc842 semantic-conventions: update to v1.4.0 spec (#570)
    • d70a537 Update example and optional dependencies (#568)
    • a2dd6e7 fix: TraceState cannot insert new key-value pairs. (#567)
    • dc7d81f Update trace flags to match spec (#565)
    • 635f10e Move unit into metrics module (#564)
    • 99e51c1 Update lib and tracing module docs with examples (#563)
    • 1ca62d3 feat: allow users to use different channels based on runtime in batch span pr...
    • fb576b0 move hyper prometheus example into something runnable (#562)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    You can trigger a rebase of this PR by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • build(deps): bump opentelemetry from 0.21.0 to 0.22.0

    build(deps): bump opentelemetry from 0.21.0 to 0.22.0

    Bumps opentelemetry from 0.21.0 to 0.22.0.

    Release notes

    Sourced from opentelemetry's releases.

    v0.22.0

    API

    Added

    Changed

    Removed

    SDK

    Deprecated

    • XrayIdGenerator in the opentelemetry-sdk has been deprecated and moved to version 0.10.0 of the opentelemetry-aws crate.

    Added

    • #1410 Add experimental synchronous gauge

    • #1471 Configure batch log record processor via OTEL_BLRP_* environment variables and via OtlpLogPipeline::with_batch_config

    • #1503 Make the documentation for In-Memory exporters visible.

    • #1526 Performance Improvement : Creating Spans and LogRecords are now faster, by avoiding expensive cloning of Resource for every Span/LogRecord.

    Changed

    • Breaking #1313 #1350 Changes how Span links/events are stored to achieve performance gains. See below for details:

      Behavior Change: When enforcing max_links_per_span, max_events_per_span from SpanLimits, links/events are kept in the first-come order. The previous "eviction" based approach is no longer performed.

      Breaking Change Affecting Exporter authors:

      SpanData now stores links as SpanLinks instead of EvictedQueue where SpanLinks is a struct with a Vec of links and dropped_count.

      SpanData now stores events as SpanEvents instead of EvictedQueue where SpanEvents is a struct with a Vec of events and dropped_count.

    • Breaking Remove TextMapCompositePropagator #1373. Use TextMapCompositePropagator in opentelemetry API.

    ... (truncated)

    Commits

    Dependabot compatibility score

    You can trigger a rebase of this PR by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
Owner
Harry Nguyen
Harry Nguyen
The Amp programming language: a language designed for building high performance systems.

A language designed for building high performance systems. Platform Support x86_64-pc-windows ✅ x86_64-unknown-linux ⚠️ untested x86_64-unknown-darwin

The Amp Programming Language 5 Mar 17, 2023
A versatile and dynamic music bot designed to elevate the musical experience within Discord servers.

Masayoshi Masayoshi is a discord music bot written in Rust for making a great experience within Discord servers with support to Youtube, SoundCloud, S

null 6 Dec 26, 2023
A library for building declarative text-based user interfaces

Intuitive docs.rs Documentation Intuitive is a component-based library for creating text-based user interfaces (TUIs) easily. It is heavily inspired b

Enrico Borba 205 Dec 29, 2022
tpp (Tera Pre-Processor) is a versatile CLI (Command Line Interface) tool crafted for preprocessing files using the Tera templating engine.

tpp (Tera Pre-Processor) is a versatile CLI (Command Line Interface) tool crafted for preprocessing files using the Tera templating engine. Drawing inspiration from pre-processors like cpp and gpp, tpp is the next evolution with its powerful expressive toolset.

null 3 Nov 23, 2023
Build terminal user interfaces and dashboards using Rust

tui-rs tui-rs is a Rust library to build rich terminal user interfaces and dashboards. It is heavily inspired by the Javascript library blessed-contri

Florian Dehau 9.3k Jan 4, 2023
A versatile and extensible logging implementation.

Logforth Project Overview A versatile and extensible logging implementation. Usage Add the dependencies to your Cargo.toml with: cargo add log cargo a

FastLabs 36 Oct 19, 2024
A Rust library for drawing grid-based user interfaces using ASCII characters.

grux A library for drawing grid-based user interfaces using ASCII characters. // Provides a uniform interface for drawing to a 2D grid. use grux::Grid

Matan Lurey 4 Jan 10, 2023
A command line tool for easily generating multiple versions of a configuration file from a single template

MultiConf A command line tool for easily generating multiple versions of a configuration file from a single template. Why? I'm a big fan of the i3 win

Ian Clarke 4 Dec 10, 2022
Ember is a minimalistic Rust library for creating 2D graphics, games, and interactive visualizations with ease and simplicity.

Ember Ember is a simple and fun 2D rendering library for Rust, allowing you to quickly create graphics and interactive applications with ease. It uses

null 8 May 4, 2023
An Interpreter for Brainfuck programming language implemented in the Rust programming language with zero dependencies.

Brainfuck Hello, Visitor! Hey there, welcome to my project showcase website! It's great to have you here. I hope you're ready to check out some awesom

Syed Vilayat Ali Rizvi 7 Mar 31, 2023