Skip to main content

Crate rust_microservice

Crate rust_microservice 

Source
Expand description

§📦 Rust Microservice

Rust Microservice Framework is a high-performance Rust crate designed to simplify the creation, configuration, and initialization of microservice-oriented web servers. It provides a unified system for handling configuration from multiple sources and a web server bootstrap layer powered by actix-web and tokio.

§✨ Features

  • Multi-source configuration management

    • YAML configuration file loading using serde_yaml and config
    • Environment variable overrides
    • Command-line parameter parsing using clap
    • Automatic deserialization into strongly typed structures using serde
  • Web server initialization

    • HTTP server powered by actix-web
    • Asynchronous runtime handled by tokio
    • Built-in routing integration for exposing microservice endpoints
    • Input/output serialization using serde_json and serde-xml-rs
  • Extensible architecture

    • Supports custom modules for controllers, services, repositories, and middleware
    • Easy integration with external crates and microservice ecosystems

§🛠️ Configuration System

The framework provides a configuration loader that merges settings from:

  1. YAML files – typically config.yaml or environment-specific variations
  2. Environment variables – allowing container-friendly overrides
  3. Command-line parameters – using clap for high-level CLI ergonomics

Configuration sources follow a layered precedence model:

Environment variables > CLI parameters > YAML configuration file

After loading the configuration, the framework exposes a typed Settings instance for application modules and endpoint handlers.

§🌐 Web SERVER Module

The server module is responsible for:

  • Initializing the actix-web HTTP server
  • Registering routers and microservice endpoints
  • Managing middlewares and shared application state
  • Running the asynchronous runtime using tokio::main or a custom runtime

This framework encourages a modular architecture where each microservice registers its own route handlers, serializers, and business logic.

§⚙️ Serialization Support

The crate includes seamless integration with:

  • JSON serialization/deserialization via serde_json
  • XML handling via serde-xml-rs

These serializers allow exposing multiple content-types or supporting legacy systems.

§⚡ Usage

Add the crate dependency in your project’s Cargo.toml:

rust-microservice = "0.1.3"

Modules§

settings
The server behavior is fully driven by a YAML configuration file. This file defines network settings, security providers, data sources, and observability integrations used at runtime.
test
🔬 Test Environment Infrastructure

Structs§

LoginForm
Represents the payload used for authentication requests following the OAuth2-style “password” or “client credentials” grant patterns.
Server
Represents the high-level server controller responsible for loading configuration, applying custom setup, and running the application.
ServerWrappers
Represents the middleware wrappers applied to the HTTP server.
Token
Represents an authentication token response typically returned by an OAuth2 / OpenID Connect authorization server.

Enums§

ServerError
Represents all possible errors that can occur within the server lifecycle.

Functions§

server_wrappers
Creates a ServerWrappers instance from the given Settings.

Type Aliases§

Result
A type alias for a Result with the ServerError error type.

Attribute Macros§

ServerApi
🔗 API Server Macro
database
🛢️ Database Macro
secured
🔐 Secured Macro