Springtime Web Axum
Web framework based on Springtime application framework and axum. Inspired by the Spring Framework in Java, Springtime Web Axum provides a way to create advanced modular Rust web applications by ensuring all components of the application are properly decoupled from each other, and are managed by the dependency injection system.
While axum
provides a way to explicitly create web handlers in an imperative
way, this crate gives the option to create multi-layer applications in a
declarative way, leveraging underlying dependency injection. This enables rapid
application development and loose coupling between components.
Features
- Automatic controller discovery (web handlers with dependency injection)
- Hierarchical router paths
- Multiple server instances support with controller filtering
- Built-in external file and programmable configuration
- Advanced router configuration
- All the features provided by
axum
Basic usage
Springtime Web Axum is highly configurable, but the most basic usage example
is quite simple and consists of declaring controllers, creating an Application
instance and calling run()
. For tutorial, advanced features, and patterns,
please look at the examples,
which form a step-by-step guide.
The following example assumes familiarity with springtime and springtime-di.
use Path;
use application;
use ComponentInstancePtr;
use ;
use controller;
// injectable example trait representing a domain service
// concrete service implementation
;
// register ExampleDomainService as providing dyn DomainService
// create a struct which will serve as our Controller - this implies it needs to be a Component for
// the dependency injection to work
// mark the struct as a Controller - this will scan all functions for the controller attributes and
// create axum handlers out of them
// note: for the sake of simplicity, errors are unwrapped, rather than gracefully handled
async