Crates.io | kanagawa |
lib.rs | kanagawa |
version | 0.1.3 |
source | src |
created_at | 2024-01-23 17:18:42.426533 |
updated_at | 2024-01-25 02:42:10.372996 |
description | Web framework based on Tide with Proactive IO |
homepage | |
repository | https://github.com/vertexclique/kanagawa |
max_upload_size | |
id | 1111024 |
size | 8,237,998 |
Kanagawa is a fork of Tide web framework. It focuses on performance rather than the convenience.
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"
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.
Benchmarked on:
Run your own benchmarks.
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]
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]
To add a link to this list, edit the markdown
file and
submit a pull request (github login required)
Please list here.
Want to join us? Check out our The "Contributing" section of the guide and take a look at some of these issues:
The Kanagawa project adheres to the Contributor Covenant Code of Conduct. This describes the minimum behavior expected from all contributors.
Licensed under either of
at your option.
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.