Module warp::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§

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

Traits§

  • Types that can be converted into a Response.

Functions§

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

Type Aliases§

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