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:
# Example, use the version numbers you need
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§
- body
- Streaming bodies for Requests and Responses
Structs§
- Body
- A stream of
Bytes, used when receiving bodies. - Context
- The context of a request.
- Error
- A http error.
- Header
Map - A set of HTTP headers
- Method
- The Request Method (VERB)
- Next
- The remainder of a middleware chain, including the endpoint.
- Request
- Represents an HTTP request.
- Response
- Represents an HTTP response
- Route
- A handle to a route.
- Server
- An HTTP server.
- Status
Code - An HTTP status code (
status-codein RFC 7230 et al.). - Uri
- The URI component of a request.
- Version
- Represents a version of the HTTP spec.
Traits§
- Endpoint
- An HTTP request handler.
- Middleware
- Middleware that wraps around the remaining middleware chain.
Functions§
- new
- Create a new Envoy server.
Type Aliases§
- Result
- A specialized Result type for Envoy.