Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zihantype/predawn
Predawn is a Rust web framework like Spring Boot -- Predawn 是一个类似 Spring Boot 的 Rust web 框架
https://github.com/zihantype/predawn
framework rust spring-boot web
Last synced: 6 days ago
JSON representation
Predawn is a Rust web framework like Spring Boot -- Predawn 是一个类似 Spring Boot 的 Rust web 框架
- Host: GitHub
- URL: https://github.com/zihantype/predawn
- Owner: ZihanType
- License: apache-2.0
- Created: 2024-03-05T16:28:47.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-10-23T01:39:48.000Z (2 months ago)
- Last Synced: 2024-10-25T04:29:57.450Z (about 2 months ago)
- Topics: framework, rust, spring-boot, web
- Language: Rust
- Homepage:
- Size: 516 KB
- Stars: 77
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Predawn
[![Crates.io version](https://img.shields.io/crates/v/predawn.svg?style=flat-square)](https://crates.io/crates/predawn)
[![docs.rs docs](https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square)](https://docs.rs/predawn)`predawn` is a Rust web framework like `Spring Boot`.
```rust
use predawn::{
app::{run_app, Hooks},
controller,
};
use rudi::Singleton;struct App;
impl Hooks for App {}
#[tokio::main]
async fn main() {
run_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](./examples/) directories.
## More complex example
```rust
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::().await;
}#[async_trait]
trait Service: Send + Sync {
fn arc(self) -> Arc
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,
}#[controller]
impl Controller {
#[endpoint(paths = ["/"], methods = [GET])]
async fn hello(&self) -> String {
self.svc.hello().await
}
}
```## Credits
- [axum](https://github.com/tokio-rs/axum)
- [poem](https://github.com/poem-web/poem)
- [loco](https://github.com/loco-rs/loco)
- [volo-http](https://github.com/cloudwego/volo)
- [salvo](https://github.com/salvo-rs/salvo)