#web-server #attributes #router #warp #attrouter #stry

macro stry-attrouter

A attribute based router for various Rust web servers

1 unstable release

0.1.0 Dec 26, 2020

#1101 in Procedural macros

MIT license

24KB
566 lines

(stry) attrouter

Attrouter is an attribute based router for various Rust web servers.

Web Servers

  • Tide
  • Warp

Examples

Add stry-attrouter, tokio, and warp to your dependencies:

stry-attrouter = { version = "0.1", default-features = false, features = [ "with-warp" ] }
tokio = { version = "0.2", features = ["full"] }
warp = "0.2"

And in your main.rs:

// GET /hello/warp => 200 OK with body "Hello, warp!"
#[stry_attrouter::get("/hello/{name}")]
fn hello(name: String) -> impl warp::Reply {
    format!("Hello, {}!", name)
}

#[tokio::main]
async fn main() {
    warp::serve(hello())
        .run(([127, 0, 0, 1], 3030))
        .await;
}

Dependencies

~1.5MB
~35K SLoC