Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kernelerr/blacktea
A new comfortable back end framework for rustaceans.
https://github.com/kernelerr/blacktea
Last synced: 25 days ago
JSON representation
A new comfortable back end framework for rustaceans.
- Host: GitHub
- URL: https://github.com/kernelerr/blacktea
- Owner: KernelErr
- License: apache-2.0
- Created: 2021-06-18T01:44:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-26T09:58:47.000Z (over 3 years ago)
- Last Synced: 2024-10-08T09:34:19.513Z (29 days ago)
- Language: Rust
- Homepage: https://blacktea.lirui.tech
- Size: 37.1 KB
- Stars: 9
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Black Tea
**Under heavy development, can not use in production environment.**
Language: [English](./README.md) | [简体中文](./README_cn.md)
> Would you like to have one cup of warm black tea?
Homepage & Document: [Black Tea(Under Construction)](https://blacktea.lirui.tech/) Discord: [Black Tea](https://discord.gg/tfE8RMx8Dr)
Black Tea is a new Rust back end framework based on hyper. We are enthusiastic to provide developers some enhanced features and comfortable coding experience.
## Quick Start
Add dependencies in `Cargo.toml`:
```toml
[dependencies]
blacktea = "0.1.1"
tokio = { version = "1", features = ["full"] }
# Enable logging
# log = "0.4"
# pretty_env_logger = "0.4"
```## Example Code
> Code below only suits with version on GitHub, for published version, please refer to Crates.
```rust
use blacktea::{App, HttpResponse, Method, PathParams, Server, URLParams};async fn url_echo(params: URLParams) -> HttpResponse {
let params = params.get("msg");
if let Some(msg) = params {
HttpResponse::Ok().text(&msg)
} else {
HttpResponse::Ok().text("Echo!")
}
}async fn path_echo(params: PathParams) -> HttpResponse {
let params = params.find("msg");
if let Some(msg) = params {
HttpResponse::Ok().text(&msg)
} else {
HttpResponse::Ok().text("Echo!")
}
}#[tokio::main]
async fn main() {
// Enable logging, set RUST_LOG=info
// pretty_env_logger::init();
let mut server = Server::new("127.0.0.1:8080");
let mut app = App::new();
// echo?msg=hello
app.add("/echo", Method::GET, url_echo);
// echo/hello
app.add("/echo/:msg", Method::GET, path_echo);
server.mount("/v1", app);
server.run().await
}
```## License
Black Tea is available under [Apache License 2.0](https://opensource.org/licenses/Apache-2.0), you are also subjected to all dependencies' licenses.