Installation
To get started with warp, you need to add it to your project's Cargo.toml file. Since warp is built on Tokio, you'll also need the tokio crate.
Dependencies
Add warp and tokio to your [dependencies] in Cargo.toml:
tokio = { version = "1", features = ["full"] }
warp = { version = "0.4", features = ["server"] }
The server feature is required to run a standalone warp server using warp::serve().
Feature Flags
warp is designed to be modular. You can enable or disable features to control which functionalities are included, helping to keep your binary size small and compile times fast. The v0.4.0 release made many features optional.
Here are the available feature flags defined in Cargo.toml:
server: Enables thewarp::serve()function and related utilities to run a standalone hyper server. This is the most common way to run awarpapplication.test: Enables thewarp::testmodule, which provides utilities for testing your filters without running a full server.multipart: Enables support formultipart/form-datarequests. This feature adds themulterdependency.websocket: Enables WebSocket support viawarp::ws. This addstokio-tungsteniteand related dependencies.compression: A meta-feature that enables both gzip and brotli compression filters.compression-gzip: Enablesgzipanddeflatecompression filters. This adds theasync-compressiondependency withdeflateandgzipfeatures.compression-brotli: Enablesbrotlicompression filter. This adds theasync-compressiondependency with thebrotlifeature.
Example: Enabling Multiple Features
If you need WebSockets and multipart forms, your Cargo.toml would look like this:
warp = { version = "0.4", features = ["server", "websocket", "multipart"] }