Crates.io | envoy_http |
lib.rs | envoy_http |
version | 0.2.2 |
source | src |
created_at | 2022-06-16 03:52:37.014708 |
updated_at | 2022-07-05 02:54:31.795609 |
description | A minimal and pragmatic Rust web application framework built for rapid development |
homepage | |
repository | https://github.com/framework-tools/envoy |
max_upload_size | |
id | 607192 |
size | 70,389 |
Envoy is a minimal and pragmatic Rust web application framework built for rapid development. It comes with a robust set of features that make building async web applications and APIs easier and more fun.
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
envoy = "0.16.0"
async-std = { version = "1.8.0", features = ["attributes"] }
serde = { version = "1.0", features = ["derive"] }
Create an HTTP server that receives a JSON body, validates it, and responds with a confirmation message.
use envoy::Context;
use envoy::prelude::*;
#[derive(Debug, Deserialize)]
struct Animal {
name: String,
legs: u16,
}
#[tokio::main]
async fn main() -> envoy::Result {
let mut app = envoy::new();
app.at("/orders/shoes").post(order_shoes);
app.listen("127.0.0.1:8080").await?;
Ok(())
}
async fn order_shoes(mut ctx: &mut Context) -> envoy::Result {
let Animal { name, legs } = ctx.body_json().await?;
Ok(format!("Hello, {}! I've put in an order for {} shoes", name, legs).into())
}
$ 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.
To add a link to this list, edit the markdown
file and
submit a pull request (github login required)
Listing here
does not constitute an endorsement or recommendation from the envoy
team. Use at your own risk.
Want to join us? Check out our The "Contributing" section of the guide and take a look at some of these issues:
The Envoy 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.