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