Crates.io | predawn |
lib.rs | predawn |
version | 0.9.0 |
source | src |
created_at | 2024-03-05 16:36:07.551337 |
updated_at | 2024-10-11 08:52:12.775107 |
description | Predawn is a Rust web framework like Spring Boot. |
homepage | https://github.com/ZihanType/predawn |
repository | https://github.com/ZihanType/predawn |
max_upload_size | |
id | 1163218 |
size | 199,987 |
predawn
is a Rust web framework like Spring Boot
.
use predawn::{
app::{run_app, Hooks},
controller,
};
use rudi::Singleton;
struct App;
impl Hooks for App {}
#[tokio::main]
async fn main() {
run_app::<App>().await;
}
#[derive(Clone)]
#[Singleton]
struct Controller;
#[controller]
impl Controller {
#[endpoint(paths = ["/"], methods = [post])]
async fn hello(&self, name: String) -> String {
format!("Hello {name}")
}
}
More examples can be found in the examples directories.
use std::sync::Arc;
use async_trait::async_trait;
use predawn::{
app::{run_app, Hooks},
controller,
};
use rudi::Singleton;
struct App;
impl Hooks for App {}
#[tokio::main]
async fn main() {
run_app::<App>().await;
}
#[async_trait]
trait Service: Send + Sync {
fn arc(self) -> Arc<dyn Service>
where
Self: Sized + 'static,
{
Arc::new(self)
}
async fn hello(&self) -> String;
}
#[derive(Clone)]
#[Singleton(binds = [Service::arc])]
struct ServiceImpl;
#[async_trait]
impl Service for ServiceImpl {
async fn hello(&self) -> String {
"Hello, World!".to_string()
}
}
#[derive(Clone)]
#[Singleton]
struct Controller {
svc: Arc<dyn Service>,
}
#[controller]
impl Controller {
#[endpoint(paths = ["/"], methods = [GET])]
async fn hello(&self) -> String {
self.svc.hello().await
}
}