24 releases (12 breaking)

0.14.0 Oct 31, 2021
0.12.0 Aug 5, 2021
0.11.3 Jul 4, 2021
0.5.0 Feb 26, 2021
0.4.0 Jan 25, 2020

#2105 in Procedural macros

Download history 510/week @ 2024-03-14 1173/week @ 2024-03-21 851/week @ 2024-03-28 593/week @ 2024-04-04 432/week @ 2024-04-11 427/week @ 2024-04-18 415/week @ 2024-04-25 339/week @ 2024-05-02 145/week @ 2024-05-09 362/week @ 2024-05-16 529/week @ 2024-05-23 467/week @ 2024-05-30 465/week @ 2024-06-06 462/week @ 2024-06-13 374/week @ 2024-06-20 536/week @ 2024-06-27

1,939 downloads per month
Used in 4 crates (via rweb)

Apache-2.0

90KB
2K SLoC

rweb

Build Status

Yet another web server framework for rust.

Installation:

[dependencies]
rweb = "0.6"
tokio = "1"

Installation (with automatic openapi generation):

[dependencies]
rweb = { version = "0.6", features = ["openapi"] }
serde = "1"
tokio = "1"

Features

  • Safe & Correct

Since rweb is based on warp, which features safety and correctness, rweb has same property.

  • Easy to read code
use rweb::*;
use serde::{Serialize, Deserialize};

#[get("/output")]
fn output() -> String {
    String::from("this returns 200 with text/plain mime type")
}

#[derive(Debug, Serialize, Deserialize, Schema)]
struct Product {
    id: String,
    title: String,
}

#[get("/products")]
fn products() -> Json<Vec<Product>> {
    // ...
    // This returns 200 with application/json
}

#[get("/products/{id}")]
fn product(id: String) -> Json<Product> {
    // ...
    // This returns 200 with application/json
}

#[get("/product")]
fn new_product(_product: Json<Product>) -> Json<Product> {
    // ...
    // This returns 200 with application/json
}

#[derive(Debug, Serialize, Deserialize, Schema)]
struct SearchOption {
    query: String,
    limit: usize,
    page_token: String,
}

#[get("/search")]
fn search(_product: Query<SearchOption>) -> Json<Vec<Product>> {
    // ...
    // This returns 200 with application/json
}

#[tokio::main]
async fn main() {
    serve(output().or(product()).or(products()).or(search())).run(([127, 0, 0, 1], 3030)).await;
}

  • Websocket

If you want to use websocket, just declare a parameter typed Ws. It's all.

use rweb::*;

#[get("/ws")]
fn example(ws: ws::Ws) -> String {
    String::new("use ws.on_upgrade or extra")
}
  • Automatic openapi spec generation

rweb supports automatically generating openapi specification file based on your code.

See: documentation for usage.

  • API UX interaction for openapi
// Build openapi for your API
let (spec, filter) = openapi::spec().build(move || {
    // Your API's filters
    math::math()
        .or(products::products())
        .or(generic::body())
        .or(generic::optional())
        .or(generic::search())
        .or(response::response())
});

println!("go to http://localhost:3030/docs to interact with your openapi!");
serve(filter.or(openapi_docs(spec)))
    .run(([127, 0, 0, 1], 3030))
    .await;

Comparison

Name rweb actix-web gotham iron nickel rocket rouille Thruster Tide tower-web warp
License license license license license license license license license license license license
Version version version version version version version version version version version version
Recent downloads recent downloads recent downloads recent downloads recent downloads recent downloads recent downloads recent downloads recent downloads recent downloads recent downloads recent downloads
Github stars github stars github stars github stars github stars github stars github stars github stars github stars github stars github stars github stars
Contributors contributors contributors contributors contributors contributors contributors contributors contributors contributors contributors contributors
Activity activity activity activity activity activity activity activity activity activity activity activity
Base framework hyper / warp tokio hyper hyper hyper hyper tiny-http tokio hyper hyper hyper
https Y Y Y ? ? ? ? ? ? ? Y
http 2 Y Y ? ? ? ? ? ? ? ? Y
async Y Y Y Y Y Y Y (via different method)
stable rust Y Y Y Y Y Y Y Y Y Y
openapi support Y

Dependencies

~4.5MB
~114K SLoC