dipper

Crates.iodipper
lib.rsdipper
version
sourcesrc
created_at2024-09-24 13:09:08.381234
updated_at2024-11-01 13:59:21.74344
descriptionAn out-of-the-box modular dependency injection web application framework.
homepagehttps://github.com/andeya/dipper
repositoryhttps://github.com/andeya/dipper
max_upload_size
id1385238
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Andeya (andeya)

documentation

https://docs.rs/dipper

README

dipper

An out-of-the-box modular dependency injection web application framework.

Crates.io Docs CI Codecov License

Install

Run the following Cargo command in your project directory:

cargo add dipper

Or add the following line to your Cargo.toml:

dipper = "0.3"

Example

use dipper::mode::ENV_DIPPER_MODE;
use dipper::prelude::*;
use std::env;

#[tokio::main]
async fn main() {
    if cfg!(debug_assertions) {
        env::set_var(ENV_DIPPER_MODE, "dev");
    }
    init_otel!();
    new_app![calculate::Calculate]
        .with_component_parameters::<calculate::Calculate>(calculate::CalculateParameters { state: 1 })
        .with_routable_preset(true)
        .run("0.0.0.0:8888")
        .await;
}

mod calculate {
    use dipper::prelude::*;
    use std::sync::Arc;

    pub trait Module: Interface {
        fn add(&self, left: i64, right: i64) -> i64;
    }

    #[derive(Clone)]
    #[dipper(Module)]
    pub struct Calculate {
        state: i64,
    }

    impl Interface for Calculate {
        fn manifest(&self) -> Manifest {
            Manifest::default().with_name("Calculate".to_owned()).with_summary("Calculate. For example, addition.".to_owned())
        }

        fn route(self: Arc<Self>, blank_router: Router) -> Router {
            blank_router
                .path("calculate")
                .push(Router::with_path("add1").get(self.add1()))
                .push(Router::with_path("add2").get(self.add2()))
                .push(Router::with_path("add3").get(Self::add3()))
        }
    }

    impl Module for Calculate {
        fn add(&self, left: i64, right: i64) -> i64 {
            ({ self.state + left + right }).instrument(info_span!("add")).into_inner()
        }
    }

    #[dipper]
    impl Calculate {
        /// doc line 1
        /// doc line 2
        #[dipper(handler)]
        fn add1(&self, left: QueryParam<i64>, right: QueryParam<i64>) -> String {
            self.add(*left, *right).to_string()
        }
        /// doc line 3
        /// doc line 4
        #[dipper(endpoint)]
        pub(crate) fn add2(self: ::std::sync::Arc<Self>, left: QueryParam<i64>, right: QueryParam<i64>) -> String {
            self.add(*left, *right).to_string()
        }
        /// doc line 5
        /// doc line 6
        #[dipper(endpoint(responses((status_code = 400, description = "Wrong request parameters."))))]
        pub fn add3(left: QueryParam<i64>, right: QueryParam<i64>, depot: &Depot) -> String {
            info!("{}", depot.obtain::<GlobalManifestMap>().unwrap().to_xml_string());
            (*left + *right).to_string()
        }
    }
}

Browse http://localhost:8888/api-doc/ and open the OpenAPI online test.

Commit count: 0

cargo fmt