springtime_web_axum/lib.rs
1//! Web framework based on [Springtime](https://crates.io/crates/springtime) and axum.
2//!
3//! `axum` is a web application framework built with a imperative approach - integration with
4//! *Springtime* allows for declarative approach to creating handlers (called here
5//! [*Controllers*](controller::Controller)) which can take full advantage of dependency injection.
6//!
7//! ### Simple usage example
8//!
9//! ```no_run
10//! use axum::extract::Path;
11//! use springtime::application;
12//! use springtime_di::Component;
13//! use springtime_web_axum::controller;
14//!
15//! // create a struct which will serve as our Controller - this implies it
16//! // needs to be a Component for the dependency injection to work
17//! #[derive(Component)]
18//! struct ExampleController;
19//!
20//! // mark the struct as a Controller - this will scan all functions for the
21//! // controller attributes and create axum handlers out of them
22//! #[controller]
23//! impl ExampleController {
24//! // this function will respond to GET request for http://localhost/ (or
25//! // any network interface)
26//! #[get("/")]
27//! async fn hello_world(&self) -> &'static str {
28//! "Hello world!"
29//! }
30//! }
31//!
32//! // note: for the sake of simplicity, errors are unwrapped, rather than
33//! // gracefully handled
34//! #[tokio::main]
35//! async fn main() {
36//! let mut application =
37//! application::create_default().expect("unable to create application");
38//!
39//! // run our server with default configuration - requests should be
40//! // forwarded to ExampleController
41//! application.run().await.expect("error running application");
42//! }
43//! ```
44//!
45//! ### Features
46//!
47//! * `derive` - automatically import helper proc macros
48
49pub mod config;
50pub mod controller;
51pub mod router;
52pub mod server;
53
54pub use axum;
55
56#[cfg(feature = "derive")]
57pub use springtime_web_axum_derive::*;