Crates.io | nano-rs |
lib.rs | nano-rs |
version | 0.1.2 |
source | src |
created_at | 2024-04-14 06:24:25.442911 |
updated_at | 2024-04-16 07:12:08.908989 |
description | Light Web Kit |
homepage | https://github.com/CloverOS/nano-rs |
repository | https://github.com/CloverOS/nano-rs |
max_upload_size | |
id | 1208049 |
size | 8,231 |
nano-rs is a lightweight, non-invasive, convention-over-configuration Rust Web service component, aimed at providing a fast and efficient development experience. By reducing the burden of configuration, it allows you to focus more on implementing business logic.
MSRV >= 1.66
cargo add nano-rs
Axum
[build-dependencies]
nano-rs = "0.1.0"
nano-rs-build = "0.1.0"
use std::error::Error;
use nano_rs_build::core::NanoBuilder;
use nano_rs::axum::gen::gen_route::AxumGenRoute;
fn main() -> Result<(), Box<dyn Error>> {
NanoBuilder::new(None).gen_api_route(AxumGenRoute::new());
Ok(())
}
port: 8888
name: example
host: 127.0.0.1
#[get(path = "/store/name", layers = ["crate::layers::auth::auth_token1"])]
pub async fn get_store_name() -> Result<RestResp<String>, ServerError> {
biz_ok("Doggy Store".to_string())
}
cargo build
routes.rs
in your src/
.routes.rs
as it will be overwritten every time you build.main.rs
. (refer to the project structure in the example)use axum::Router;
use nano_rs::axum::start::run;
use nano_rs::config::init_config_with_cli;
use nano_rs::config::rest::RestConfig;
use crate::routes::get_routes;
mod routes;
mod layers;
mod api;
#[tokio::main]
async fn main() {
let rest_config = init_config_with_cli::<RestConfig>();
let _guard = nano_rs::tracing::init_tracing(&rest_config);
let service_context = ServiceContext {
rest_config: rest_config.clone(),
};
let app = Router::new().nest(
rest_config.base_path.as_str(),
get_routes(service_context.clone(), rest_config.clone()),
);
run(app, rest_config).await
}
#[derive(Clone)]
pub struct ServiceContext {
pub rest_config: RestConfig,
}
cargo run -- --config etc/config.yaml
For a full list of proposed features (and known issues), please see the open issues.
Distributed under the MIT License. For more information, see LICENSE.txt
.