= REST library for {{ title }} {{description}} == Overview This server was generated from OpenAPI specification by the link:https://gitlab.com/argentum-toolkit/argentum(argentum-rest-generator). - API version: {{ version }} - Package Name: {{ packageName }} {{#if homepage}} - Home page: {{ homepage }} {{/if}} {{#if repository}} - Repository: {{ repository }} {{/if}} {{#if documentation}} - Home page: {{ documentation }} {{/if}} {{#if license}} - License: `{{ license.name }}`{{#if license.url}} link:{{ license.url }}[]{{/if}} {{/if}} == How to use === Create server application ==== Clone this repository or publish it as a crate {{#if repository}} [source,bash] .... $ git clone {{ repository }} rest .... {{/if}} link:https://doc.rust-lang.org/cargo/commands/cargo-publish.html[How to publish] ==== Create application [source,bash] .... $ cargo new app --name {{ packageName }}_app $ cd app .... ==== Add dependencies .Cargo.toml example [source,toml] .... [package] name = "{{ packageName }}_app" description = "{{ title }}" version = "{{ version }}" edition = "2021" [dependencies] argentum_log_business = { {{#if argentumPath}}path = "{{argentumPath}}/argentum_log/business", {{/if}}version = ">=0.2.0-dev,<0.3.0" } argentum_log_infrastructure = { {{#if argentumPath}}path = "{{argentumPath}}/argentum_log/infrastructure", {{/if}}version = ">=0.2.0-dev,<0.3.0" } argentum_rest_infrastructure = { {{#if argentumPath}}path = "{{argentumPath}}/argentum_rest/infrastructure", {{/if}}version = ">=0.2.0-dev,<0.3.0" } argentum_standard_business = { {{#if argentumPath}}path = "{{argentumPath}}/argentum_standard/business", {{/if}}version = ">=0.2.0-dev,<0.3.0" } argentum_user_business = { {{#if argentumPath}}path = "{{argentumPath}}/argentum_user/business", {{/if}}version = ">=0.2.0-dev,<0.3.0" } {{#if packageName }} {{ packageName }} = { path = "../rest" } {{ else }} {{ packageName }} = "*" {{/if}} tokio = { version = "1.34.*", features = ["full"] } .... .main.rs [source,rust] .... mod di; use crate::di::di_factory; #[tokio::main] async fn main() -> Result<(), Box> { let di = di_factory().await; di.server.serve().await } .... .di.rs [source,rust] .... use argentum_log_business::{DefaultLogger, Level}; use argentum_log_infrastructure::stdout::PrettyWriter; use argentum_rest_infrastructure::service::{RouterCombinator, Server}; use std::net::SocketAddr; use argentum_rest_infrastructure::RestDiC; use argentum_user_business::use_case::user_authenticates_with_token::UserAuthenticatesWithTokenUc; use {{ packageName }}::ApiDiC; use std::sync::Arc; pub struct DiC { // Public services pub server: Arc, } impl DiC { pub fn new(server: Arc) -> DiC { DiC { server } } } pub async fn di_factory() -> DiC { let log_writer = Arc::new(PrettyWriter::new()); let logger = Arc::new(DefaultLogger::new(Level::Trace, log_writer)); //TODO: create instance of let user_authenticates_with_token_uc: Arc; // ... let rest_di = RestDiC::new(logger.clone(), user_authenticates_with_token_uc); let u_api_di = ApiDiC::new( "/api/v1".to_string(), rest_di.request_transformer.clone(), rest_di.bearer_authenticator.clone(), // Implementations of handler traits (`use {{ packageName }}::server::handler::*`) //... rest_di.error_pre_handler.clone(), ); let listen = "0.0.0.0:8080"; // or something like that: // let listen = "172.18.0.1:8080"; // let listen = "127.0.0.1:8080"; let addr: SocketAddr = listen.parse().expect("Unable to parse socket address"); let router = Arc::new(RouterCombinator::new( vec![ u_api_di.router, //other routers ], rest_di.error_pre_handler, )); let server = Arc::new(Server::new( addr, router, // or just u_api_di.router rest_di.response_transformer, rest_di.error_handler, logger, )); DiC::new(server) } ....