Expand description
Contains the user-facing API for creating replies.
Structs§
- Problem
Details - Structured error response shaped like an RFC 7807 Problem Details document, plus arbitrary extension members that get serialized into the JSON body.
- Reply
Spec - 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 withReplySpec::done(which yields aReplyData::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/retryfields. The wire encoding is handled bySseEvent::to_bytes— embedded newlines indatabecome multipledata:lines, the way the spec requires.
Enums§
- Reply
Data - The concrete payload of a successful reply. The
Finalizerturns it into an HTTP response. Build one with thereply!macro or thereply::*constructor functions rather than by hand. - WebError
- An error returned from a handler, a
preparehook, or middleware. Each variant maps to an HTTP status the framework renders as the response (WebError::Problemas anapplication/problem+jsonbody).
Functions§
- build_
reply - Start a
ReplySpecbuilder for a reply that needs an explicit status and/or headers on top of its body. - bytes
- Build a
ReplyData::Byteswith an explicitContent-Type. The content-type is required: there is no honest default for arbitrary bytes, andapplication/octet-streammasquerading 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 Contentunless a status is set viabuild_reply). - json
- Build a JSON
ReplyDatafrom anySerializevalue. - sse
- Build a streaming Server-Sent Events response from a stream of
SseEvents. SetsContent-Type: text/event-streamandCache-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 rawserde_json::Erroron failure so callers (notably thereply!macro) can map it to a structured response instead of panicking.
Type Aliases§
- Body
Stream - A boxed,
Send + Syncstream of body chunks, used byReplyData::Streamand SSE responses. - Reply
- A handler’s return type:
Ok(ReplyData)for a success payload, orErr(WebError)for an error the framework renders as an HTTP error response. Thereply!macro produces theOkside.