[][src]Module warp::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:

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::get2().and(empty_200)
    .or(warp::post2().and(custom));

Structs

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.