API Reference

Warp

Composable web framework for Rust built on filters, combining routes and extractors into services.

Official Documentation ↗
CompatibilityThis documentation covers version warp 0.3 / Rust 1.65+. Check the official docs for the latest API surface.

Installation

cargocargo add warp

Methods

Overview

Warp builds web services from composable filters. Each filter matches part of a request and extracts typed values, and filters combine into complete routes.

Core Methods

path, method and body filters match and extract, map and and_then transform results, and reject plus recover handle errors. serve binds the composed route to a socket.

Usage Notes

Compose small filters for clarity, share state via Arc, and map rejections to consistent error responses. Filters can be unit tested by calling them directly with requests.

Common Pitfalls

Filter order affects matching and extraction, so misordered composition yields confusing rejections. Unhandled rejections produce generic errors, so add recovery. Cloning large state per request wastes memory; share via Arc.

FAQ

What is a filter?
A filter asynchronously matches a request and extracts values. Filters compose with and and or, so routes are built from small, testable pieces.
How do I return errors with status codes?
Return Rejection or reject with warp::reject, and use recover to map rejections to JSON error responses with appropriate status codes.
How do I share application state?
Use warp::any().map with an Arc clone or the with_state mechanism so handlers receive shared services without cloning heavy data per request.