kdy1/rweb

Yet another web server framework for rust

Rust

358

92 commits

updated Apr 21, 2024

See the code

README

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

Namerwebactix-webgothamironnickelrocketrouilleThrusterTidetower-webwarp
Licenselicenselicenselicenselicenselicenselicenselicenselicenselicenselicenselicense
Versionversionversionversionversionversionversionversionversionversionversionversion
Recent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloads
Github starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub stars
Contributorscontributorscontributorscontributorscontributorscontributorscontributorscontributorscontributorscontributorscontributorscontributors
Activityactivityactivityactivityactivityactivityactivityactivityactivityactivityactivityactivity
Base frameworkhyper / warptokiohyperhyperhyperhypertiny-httptokiohyperhyperhyper
httpsYYY???????Y
http 2YY????????Y
asyncYYYYYYY (via different method)
stable rustYYYYYYYYYY
openapi supportY

kdy1/rweb

Yet another web server framework for rust

Rust

358

92 commits

updated Apr 21, 2024

See the code

README

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

Namerwebactix-webgothamironnickelrocketrouilleThrusterTidetower-webwarp
Licenselicenselicenselicenselicenselicenselicenselicenselicenselicenselicenselicense
Versionversionversionversionversionversionversionversionversionversionversionversion
Recent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloadsrecent downloads
Github starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub starsgithub stars
Contributorscontributorscontributorscontributorscontributorscontributorscontributorscontributorscontributorscontributorscontributorscontributors
Activityactivityactivityactivityactivityactivityactivityactivityactivityactivityactivityactivity
Base frameworkhyper / warptokiohyperhyperhyperhypertiny-httptokiohyperhyperhyper
httpsYYY???????Y
http 2YY????????Y
asyncYYYYYYY (via different method)
stable rustYYYYYYYYYY
openapi supportY

Project health

Overall

3.7/10

Maintained

0/10

Code review

5/10
OpenSSF Scorecard

crates.io

Latest release

0.15.0 · Oct 31, 2021

Releases this year

0

Significant stargazers

Ophir LOJKINE

651 followers · starred Feb 2020

meh.

915 followers · starred Mar 2020

Fabian-Lars

372 followers · starred Jan 2021

chansuke

96 followers · starred Feb 2021