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 the warp::serve() function and related utilities to run a standalone hyper server. This is the most common way to run a warp application.
  • test: Enables the warp::test module, which provides utilities for testing your filters without running a full server.
  • multipart: Enables support for multipart/form-data requests. This feature adds the multer dependency.
  • websocket: Enables WebSocket support via warp::ws. This adds tokio-tungstenite and related dependencies.
  • compression: A meta-feature that enables both gzip and brotli compression filters.
  • compression-gzip: Enables gzip and deflate compression filters. This adds the async-compression dependency with deflate and gzip features.
  • compression-brotli: Enables brotli compression filter. This adds the async-compression dependency with the brotli feature.

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"] }