Crate envoy_http
source · [−]Expand description
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.
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:
envoy = "0.14.0"
async-std = { version = "1.6.0", features = ["attributes"] }
serde = { version = "1.0", features = ["derive"] }Examples
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(ctx: &mut Context) -> envoy::Result {
let Animal { name, legs } = ctx.body_json().await?;
Ok(ctx.res.set_body(format!("Hello, {}! I've put in an order for {} shoes", name, legs)))
}Re-exports
pub use hyper::http;Modules
Streaming bodies for Requests and Responses
Structs
A stream of Bytes, used when receiving bodies.
The context of a request.
A http error.
A set of HTTP headers
The Request Method (VERB)
The remainder of a middleware chain, including the endpoint.
Represents an HTTP request.
Represents an HTTP response
A handle to a route.
An HTTP server.
An HTTP status code (status-code in RFC 7230 et al.).
The URI component of a request.
Represents a version of the HTTP spec.
Traits
An HTTP request handler.
Middleware that wraps around the remaining middleware chain.
Functions
Create a new Envoy server.
Type Definitions
A specialized Result type for Envoy.
