Crates.io | rupring |
lib.rs | rupring |
version | 0.10.0 |
source | src |
created_at | 2023-10-10 15:56:21.652799 |
updated_at | 2024-10-04 15:42:59.820932 |
description | Spring Comes to Rust |
homepage | https://github.com/myyrakle/rupring/blob/master/README.md |
repository | https://github.com/myyrakle/rupring |
max_upload_size | |
id | 999257 |
size | 1,972,474 |
Spring Comes to Rust
required dependency list
rupring = "0.9.1"
serde = { version="1.0.193", features=["derive"] }
And you can write your server like this:
#[derive(Debug, Clone, Copy)]
#[rupring::Module(controllers=[HomeController{}], modules=[])]
pub struct RootModule {}
#[derive(Debug, Clone)]
#[rupring::Controller(prefix=/, routes=[hello, echo])]
pub struct HomeController {}
#[rupring::Get(path = /)]
pub fn hello(_request: rupring::Request) -> rupring::Response {
rupring::Response::new().text("Hello, World!".to_string())
}
#[rupring::Get(path = /echo)]
pub fn echo(request: rupring::Request) -> rupring::Response {
rupring::Response::new().text(request.body)
}
fn main() {
rupring::run(RootModule {})
}
And if you run the program, it will work fine.
Please refer to the documentation for more details.