[−][src]Module rweb::reply
Reply to requests.
A Reply
is a type that can be converted into an HTTP
response to be sent to the client. These are typically the successful
counterpart to a rejection.
The functions in this module are helpers for quickly creating a reply.
Besides them, you can return a type that implements Reply
. This
could be any of the following:
http::Response<impl Into<hyper::Body>
String
&'static str
http::StatusCode
Example
use warp::{Filter, http::Response}; // Returns an empty `200 OK` response. let empty_200 = warp::any().map(warp::reply); // Returns a `200 OK` response with custom header and body. let custom = warp::any().map(|| { Response::builder() .header("my-custom-header", "some-value") .body("and a custom body") }); // GET requests return the empty 200, POST return the custom. let routes = warp::get().and(empty_200) .or(warp::post().and(custom));
Structs
Json | A JSON formatted reply. |
WithHeader | Wraps an |
WithStatus | Wrap an |
Traits
Reply | Types that can be converted into a |
Functions
html | Reply with a body and |
json | Convert the value into a |
reply | Returns an empty |
with_header | Wrap an |
with_status | Wrap an |
Type Definitions
Response | Response type into which types implementing the |