Recipe
Warp (Rust) primer
Warp is a composable, async web framework for Rust built on Tokio and Hyper. It models routes as Filters that you combine with and and or. This primer walks through wiring a tiny JSON API you can drop into a Meridian sidecar service in under five minutes.
1.Project setup
Create a new Cargo binary crate and add Warp plus Tokio with the full feature set. Serde handles the JSON glue.
[package]
name = "warp-primer"
version = "0.1.0"
edition = "2021"
[dependencies]
warp = "0.3"
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"2.Compose two filters
Define a GET /health probe and a POST /echo endpoint. Each route is a value; combining them with.or() is how the router grows without macros.
use warp::Filter;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct Echo { message: String }
#[tokio::main]
async fn main() {
let health = warp::path("health")
.map(|| warp::reply::json(&serde_json::json!({ "ok": true })));
let echo = warp::path("echo")
.and(warp::post())
.and(warp::body::json())
.map(|e: Echo| warp::reply::json(&e));
let routes = health.or(echo);
warp::serve(routes).run(([0, 0, 0, 0], 3030)).await;
}3.Run and verify
Run cargo run --release and hit the service on port 3030. Warp's filter algebra means adding auth, rate limiting, or CORS is just another.and() in the chain — no router config to maintain.