4 releases

0.1.3 Jan 25, 2024
0.1.2 Jan 25, 2024
0.1.1 Jan 24, 2024
0.1.0 Jan 23, 2024

#96 in HTTP server

Download history 20/week @ 2024-01-21 66/week @ 2024-01-28 62/week @ 2024-02-04 20/week @ 2024-02-11 10/week @ 2024-02-18 63/week @ 2024-02-25 38/week @ 2024-03-03 1/week @ 2024-03-10 60/week @ 2024-03-31

63 downloads per month

MIT/Apache

8MB
2.5K SLoC

Kanagawa

Serve the web with Proactive IO

Kanagawa is a fork of Tide web framework. It focuses on performance rather than the convenience.

Getting started

In order to build a web app in Rust you need an HTTP server, and an async runtime. After running cargo init add the following lines to your Cargo.toml file:

# Example, use the version numbers you need
kanagawa = "0.1"

Examples

Create an HTTP server that receives a JSON body, validates it, and responds with a confirmation message.

use kanagawa::Request;
use kanagawa::prelude::*;

#[derive(Debug, Deserialize)]
struct Animal {
    name: String,
    legs: u16,
}

async fn server() -> kanagawa::Result<()> {
    let mut app = kanagawa::new();
    app.at("/orders/shoes").post(order_shoes);
    app.listen("127.0.0.1:8080").await?;
    Ok(())
}

async fn order_shoes(mut req: Request<()>) -> kanagawa::Result {
    let Animal { name, legs } = req.body_json().await?;
    Ok(format!("Hello, {}! I've put in an order for {} shoes", name, legs).into())
}

fn main() -> Result<()> {
  block_on(server())
}
$ curl localhost:8080/orders/shoes -d '{ "name": "Chashu", "legs": 4 }'
Hello, Chashu! I've put in an order for 4 shoes
$ curl localhost:8080/orders/shoes -d '{ "name": "Mary Millipede", "legs": 750 }'
Hello, Mary Millipede! I've put in an order for 750 shoes

See more examples in the examples directory.

Benchmarks

Benchmarked on:

  • Intel(R) Xeon(R) W-2295 CPU @ 3.00GHz with single NUMA node over 18 cores.
  • 200 GB RAM
  • Governor disabled.
  • Frequency scaling disabled.
  • intel pstate turbo disabled.

Run your own benchmarks.

Kanagawa (sha: 12723d8)

plain                   time:   [1.1975 µs 1.1993 µs 1.2013 µs]

nested                  time:   [1.2742 µs 1.2784 µs 1.2828 µs]

route-match             time:   [1.2299 µs 1.2336 µs 1.2384 µs]

route-root              time:   [1.2279 µs 1.2316 µs 1.2358 µs]

Tide (sha: b32f680)

plain                   time:   [1.7027 µs 1.7035 µs 1.7049 µs]

nested                  time:   [1.6998 µs 1.7005 µs 1.7014 µs]

route-match             time:   [1.7031 µs 1.7036 µs 1.7042 µs]

route-root              time:   [1.7021 µs 1.7030 µs 1.7041 µs]

Community Resources

To add a link to this list, edit the markdown file and submit a pull request (github login required)
Please list here.

Contributing

Want to join us? Check out our The "Contributing" section of the guide and take a look at some of these issues:

Conduct

The Kanagawa project adheres to the Contributor Covenant Code of Conduct. This describes the minimum behavior expected from all contributors.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~15–29MB
~454K SLoC