warp/
lib.rs

1#![deny(missing_docs)]
2#![deny(missing_debug_implementations)]
3#![deny(rust_2018_idioms)]
4#![cfg_attr(test, deny(warnings))]
5
6//! # warp
7//!
8//! warp is a super-easy, composable, web server framework for warp speeds.
9//!
10//! Thanks to its [`Filter`][Filter] system, warp provides these out of the box:
11//!
12//! - Path routing and parameter extraction
13//! - Header requirements and extraction
14//! - Query string deserialization
15//! - JSON and Form bodies
16//! - Multipart form data
17//! - Static Files and Directories
18//! - Websockets
19//! - Access logging
20//! - Etc
21//!
22//! Since it builds on top of [hyper](https://hyper.rs), you automatically get:
23//!
24//! - HTTP/1
25//! - HTTP/2
26//! - Asynchronous
27//! - One of the fastest HTTP implementations
28//! - Tested and **correct**
29//!
30//! ## Filters
31//!
32//! The main concept in warp is the [`Filter`][Filter], which allows composition
33//! to describe various endpoints in your web service. Besides this powerful
34//! trait, warp comes with several built in [filters](filters/index.html), which
35//! can be combined for your specific needs.
36//!
37//! As a small example, consider an endpoint that has path and header requirements:
38//!
39//! ```
40//! use warp::Filter;
41//!
42//! let hi = warp::path("hello")
43//!     .and(warp::path::param())
44//!     .and(warp::header("user-agent"))
45//!     .map(|param: String, agent: String| {
46//!         format!("Hello {}, whose agent is {}", param, agent)
47//!     });
48//! ```
49//!
50//! This example composes several [`Filter`s][Filter] together using `and`:
51//!
52//! - A path prefix of "hello"
53//! - A path parameter of a `String`
54//! - The `user-agent` header parsed as a `String`
55//!
56//! These specific filters will [`reject`][reject] requests that don't match
57//! their requirements.
58//!
59//! This ends up matching requests like:
60//!
61//! ```notrust
62//! GET /hello/sean HTTP/1.1
63//! Host: hyper.rs
64//! User-Agent: reqwest/v0.8.6
65//!
66//! ```
67//! And it returns a response similar to this:
68//!
69//! ```notrust
70//! HTTP/1.1 200 OK
71//! Content-Length: 41
72//! Date: ...
73//!
74//! Hello sean, whose agent is reqwest/v0.8.6
75//! ```
76//!
77//! Take a look at the full list of [`filters`](filters/index.html) to see what
78//! you can build.
79//!
80//! ## Testing
81//!
82//! Testing your web services easily is extremely important, and warp provides
83//! a [`test`](mod@self::test) module to help send mocked requests through your service.
84//!
85//! [Filter]: trait.Filter.html
86//! [reject]: reject/index.html
87
88#[macro_use]
89mod error;
90mod filter;
91pub mod filters;
92mod generic;
93pub mod redirect;
94pub mod reject;
95pub mod reply;
96mod route;
97mod server;
98mod service;
99pub mod test;
100#[cfg(feature = "tls")]
101mod tls;
102mod transport;
103
104pub use self::error::Error;
105pub use self::filter::Filter;
106// This otherwise shows a big dump of re-exports in the doc homepage,
107// with zero context, so just hide it from the docs. Doc examples
108// on each can show that a convenient import exists.
109#[cfg(feature = "compression")]
110#[doc(hidden)]
111pub use self::filters::compression;
112#[cfg(feature = "multipart")]
113#[doc(hidden)]
114pub use self::filters::multipart;
115#[cfg(feature = "websocket")]
116#[doc(hidden)]
117pub use self::filters::ws;
118#[doc(hidden)]
119pub use self::filters::{
120    addr,
121    // any() function
122    any::any,
123    body,
124    cookie,
125    // cookie() function
126    cookie::cookie,
127    cors,
128    // cors() function
129    cors::cors,
130    ext,
131    fs,
132    header,
133    // header() function
134    header::header,
135    host,
136    log,
137    // log() function
138    log::log,
139    method::{delete, get, head, method, options, patch, post, put},
140    path,
141    // path() function and macro
142    path::path,
143    query,
144    // query() function
145    query::query,
146    sse,
147    trace,
148    // trace() function
149    trace::trace,
150};
151// ws() function
152pub use self::filter::wrap_fn;
153#[cfg(feature = "websocket")]
154#[doc(hidden)]
155pub use self::filters::ws::ws;
156#[doc(hidden)]
157pub use self::redirect::redirect;
158#[doc(hidden)]
159#[allow(deprecated)]
160pub use self::reject::{reject, Rejection};
161#[doc(hidden)]
162pub use self::reply::{reply, Reply};
163#[cfg(feature = "tls")]
164pub use self::server::TlsServer;
165pub use self::server::{serve, Server};
166pub use self::service::service;
167#[doc(hidden)]
168pub use http;
169#[doc(hidden)]
170pub use hyper;
171
172#[doc(hidden)]
173pub use bytes::Buf;
174#[doc(hidden)]
175pub use futures_util::{Future, Sink, Stream};
176#[doc(hidden)]
177
178pub(crate) type Request = http::Request<hyper::Body>;