Module reply

Source
Expand description

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:

§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§

Html
An HTML reply.
Json
A JSON formatted reply.
WithHeader
Wraps an impl Reply and adds a header when rendering.
WithStatus
Wrap an impl Reply to change its StatusCode.

Traits§

Reply
Types that can be converted into a Response.

Functions§

html
Reply with a body and content-type set to text/html; charset=utf-8.
json
Convert the value into a Reply with the value encoded as JSON.
reply
Returns an empty Reply with status code 200 OK.
with_header
Wrap an impl Reply to add a header when rendering.
with_status
Wrap an impl Reply to change its StatusCode.

Type Aliases§

Response
Response type into which types implementing the Reply trait are convertable.