8 breaking releases

0.9.0 Oct 11, 2024
0.7.0 Apr 16, 2024
0.4.0 Mar 23, 2024

#2330 in Web programming

Download history 2/week @ 2024-07-20 14/week @ 2024-07-27 1/week @ 2024-08-03 6/week @ 2024-08-24 13/week @ 2024-08-31 210/week @ 2024-09-14 29/week @ 2024-09-21 20/week @ 2024-09-28 120/week @ 2024-10-05 65/week @ 2024-10-12 7/week @ 2024-10-19 3/week @ 2024-10-26 5/week @ 2024-11-02

193 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

28KB
659 lines

Predawn

Crates.io version docs.rs docs

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}")
    }
}

Features

  • Built-in OpenAPI support.
  • Automatic dependency injection.
  • Programmable configuration.

More examples can be found in the examples directories.

More complex example

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
    }
}

Credits

Dependencies

~2–3MB
~55K SLoC