Skip to main content

Module reply

Module reply 

Source
Expand description

Contains the user-facing API for creating replies.

Structs§

ProblemDetails
Structured error response shaped like an RFC 7807 Problem Details document, plus arbitrary extension members that get serialized into the JSON body.
ReplySpec
A builder for a reply with an explicit status and/or headers wrapped around a payload. Start one with build_reply, chain the setters, and finish with ReplySpec::done (which yields a ReplyData::Rich).
SseEvent
One frame in a Server-Sent Events stream. A frame may carry data (the common case), a comment (heartbeats and debug pings), and the optional event / id / retry fields. The wire encoding is handled by SseEvent::to_bytes — embedded newlines in data become multiple data: lines, the way the spec requires.

Enums§

ReplyData
The concrete payload of a successful reply. The Finalizer turns it into an HTTP response. Build one with the reply! macro or the reply::* constructor functions rather than by hand.
WebError
An error returned from a handler, a prepare hook, or middleware. Each variant maps to an HTTP status the framework renders as the response (WebError::Problem as an application/problem+json body).

Functions§

build_reply
Start a ReplySpec builder for a reply that needs an explicit status and/or headers on top of its body.
bytes
Build a ReplyData::Bytes with an explicit Content-Type. The content-type is required: there is no honest default for arbitrary bytes, and application/octet-stream masquerading as one tends to cause more bugs than it fixes (browsers guess; downstream HTTP caches mis-cache). Pass the right media type at the call site.
empty
An empty-body reply (204 No Content unless a status is set via build_reply).
json
Build a JSON ReplyData from any Serialize value.
sse
Build a streaming Server-Sent Events response from a stream of SseEvents. Sets Content-Type: text/event-stream and Cache-Control: no-cache (without which an intermediate cache might hold the live stream, defeating the point).
stream
Build a streaming-body reply from a stream of byte chunks. The body is written out as the stream yields, not buffered.
try_json
Fallible counterpart of json. Returns the raw serde_json::Error on failure so callers (notably the reply! macro) can map it to a structured response instead of panicking.

Type Aliases§

BodyStream
A boxed, Send + Sync stream of body chunks, used by ReplyData::Stream and SSE responses.
Reply
A handler’s return type: Ok(ReplyData) for a success payload, or Err(WebError) for an error the framework renders as an HTTP error response. The reply! macro produces the Ok side.