A new comfortable back end framework for rustaceans.

Related tags

Utilities blacktea
Overview

Black Tea

Under heavy development, can not use in production environment.

Language: English | 简体中文

Would you like to have one cup of warm black tea?

Homepage & Document: Black Tea(Under Construction) Discord: Black Tea

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:

[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.

HttpResponse { let params = cxt.path_params("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, Box::new(url_echo)); // echo/hello app.add("/echo/:msg",Method::GET, Box::new(path_echo)); server.mount("/v1", app); server.run().await } ">
use blacktea::{Server, HttpResponse, Method, App, Context};

async fn url_echo(cxt: Context) -> HttpResponse {
    let params = cxt.url_params("msg");
    if let Some(msg) = params {
        HttpResponse::Ok().text(&msg)
    } else {
        HttpResponse::Ok().text("Echo!")
    }
}

async fn path_echo(cxt: Context) -> HttpResponse {
    let params = cxt.path_params("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, Box::new(url_echo));
    // echo/hello
    app.add("/echo/:msg",Method::GET, Box::new(path_echo));
    server.mount("/v1", app);
    server.run().await
}

Contribution

Currently Black Tea needs your contribution! To be one of us quickly, you can contact with KernelErr directly to get a brief view of this project.

License

Black Tea is available under Apache License 2.0, you are also subjected to all dependencies' licenses.

You might also like...
Better error messages for axum framework.

axum-debug This is a debugging crate that provides better error messages for axum framework. axum is a great framework for developing web applications

Rust implementation of the Edge IoT framework

A Rust-based implementation of Edge-rs for the Raspberry Pi Pico Getting started For more details see the following article on getting started for get

tracing - a framework for instrumenting Rust programs to collect structured, event-based diagnostic information

tracing-appender Writers for logging events and spans Documentation | Chat Overview tracing is a framework for instrumenting Rust programs to collect

Rate limit middleware for poem web framework

Rate limit middleware for Poem framework Usage Check examples, poem-ratelimit is available on crates.io. A yaml configuration file is used to set limi

Ector is an open source async, no-alloc actor framework for embedded devices

Ector is an open source async, no-alloc actor framework for embedded devices. Ector is an open source async, no-alloc actor framework for embedded dev

Functional testing framework for AVR binaries, powered by simavr.

Functional testing framework for AVR binaries, powered by simavr. tl;dr get your microcontroller's firmware black-box-tested in seconds!

Examples of how to use Rust with Serverless Framework, Lambda, API Gateway v1 and v2, SQS, GraphQL, etc

Rust Serverless Examples All examples live in their own directories: project: there is nothing here, just a simple cargo new project_name with a custo

A rust `tracing` compatible framework inspired by log4rs.

trace4rs This crate allows users to configure output from tracing in the same way as you would configure the output of log4rs. Overview For a usage ex

Monorep for fnRPC (high performance serverless rpc framework)

fnrpc Monorep for fnRPC (high performance serverless rpc framework) cli Cli tool help build and manage functions Create RPC functions Create & Manage

Comments
  • Unnessary async in `fn not_found_handler()`, beacause this function doesn't have await statement

    Unnessary async in `fn not_found_handler()`, beacause this function doesn't have await statement

    warning: unused `async` for function with no await statements
      --> src/router.rs:89:1
       |
    89 | / async fn not_found_handler() -> HttpResponse {
    90 | |     HttpResponse::from_builder(
    91 | |         Response::builder()
    92 | |             .status(StatusCode::NOT_FOUND)
    ...  |
    95 | |     )
    96 | | }
       | |_^
       |
       = note: `-W clippy::unused-async` implied by `-W clippy::pedantic`
       = help: consider removing the `async` from this function
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_async
    

    async fn not_found_handler() should remove async

    opened by pymongo 0
Owner
Rui Li
Microsoft Learn Student Ambassador. Contact me: lr_cn[at]outlook.com
Rui Li
Fegeya Gretea (aka green tea), new generation programming language.

Fegeya Gretea Gretea (aka green tea), new generation programming language. A taste of Gretea's syntax: import tea.green.fmt module hello { fn hel

Ferhat Geçdoğan 13 Sep 28, 2022
An RSS feed aggregator that notifies you of new posts via email.

Rss2Email A small program capable of aggregating content from multiple RSS/Atom feeds and mailing them to you in a practical summary email. Keep track

Tony 18 Dec 18, 2022
A lightweight new Bing (AI chat) desktop application which based on Tauri.

Bing Lite A lightweight new Bing (AI chat) desktop application which based on Tauri. No more Microsoft Edge, no more Chromium/Electron! Download The l

a.e. 6 Apr 5, 2023
A W.I.P desktop application for a new typesetting language, typst.

[WIP] typstudio A W.I.P desktop application for a new markup-based typesetting language, typst. Typstudio is built using Tauri. Features Syntax highli

Cubxity 40 Apr 25, 2023
Select any exported function in a dll as the new dll's entry point.

Description This tool will patch the entry point of the input dll and replace it with the RVA of another exported function in that same dll. This allo

Kurosh Dabbagh Escalante 43 Jun 7, 2023
Framework is a detector for different frameworks in one projects

Framework is a detector for different frameworks in one projects Usage use

Inherd OS Team (硬核开源小组) 3 Oct 24, 2022
Minimal, flexible framework for implementing solutions to Advent of Code in Rust

This is advent_of_code_traits, a minimal, flexible framework for implementing solutions to Advent of Code in Rust.

David 8 Apr 17, 2022
A framework for iterating over collections of types implementing a trait without virtual dispatch

zero_v Zero_V is an experiment in defining behavior over collections of objects implementing some trait without dynamic polymorphism.

null 13 Jul 28, 2022
Doku is a framework for building documentation with code-as-data methodology in mind.

Doku is a framework for building documentation with code-as-data methodology in mind. Say goodbye to stale, hand-written documentation - with D

ANIXE 73 Nov 28, 2022
Another Async IO Framework based on io_uring

kbio, the Async IO Framework based on io_uring, is used in KuiBaDB to implement async io. Features Support multi-threading concurrent task submission.

KuiBaDB 59 Oct 31, 2022