pub struct Reply { /* private fields */ }
Expand description
A successful response with JSON data to be sent back to the client.
There are two kinds of replies. Static replies represent JSON data that is ready. Most requests
return static replies. Streaming replies represent a stream of JSON data that will stream from
a Channel
directly to the client. You can’t access the data of a streaming reply through the
Reply
struct, since it’s not ready yet. If you want to transform or edit the reply data for a
stream, you’ll need to implement a custom Channel
instead.
These are several ways to create a Reply:
- pass a Request to an Adapter to get a static response from a database
- pass a Request to a Channel to get a streaming response
- in your custom Resource, call
request.into_reply(data)
to create a Reply object.
Reply implements IntoFuture
, so you can return it directly from a and_then
block.
Implementations§
Source§impl Reply
impl Reply
pub fn data(&self) -> Option<&JsonObject>
Sourcepub fn data_mut(&mut self) -> Option<&mut JsonObject>
pub fn data_mut(&mut self) -> Option<&mut JsonObject>
Examples found in repository?
examples/4.rs (line 14)
8fn main() {
9 let mut server = Server::new();
10 let database = memory::MemoryAdapter::new();
11 server.resource("/cats", move |req: Request| {
12 database.handle(req).and_then(|mut reply| {
13 {
14 let mut data = reply.data_mut().unwrap();
15 data.insert("example".to_string(), json!("data"));
16 }
17 reply
18 })
19 });
20 server.listen("127.0.0.1:3000");
21}
pub fn to_http(self) -> Response<Body>
pub fn method(&self) -> Method
pub fn resource(&self) -> &str
pub fn id(&self) -> &Option<String>
pub fn params(&self) -> &JsonObject
pub fn param(&self, key: &str) -> &JsonValue
pub fn boxed(self) -> BoxFuture<Reply, Error>
pub fn request_data(&self) -> &JsonObject
Trait Implementations§
Source§impl IntoFuture for Reply
impl IntoFuture for Reply
Source§fn into_future(self) -> Self::Future
fn into_future(self) -> Self::Future
Consumes this object and produces a future.
Auto Trait Implementations§
impl Freeze for Reply
impl !RefUnwindSafe for Reply
impl Send for Reply
impl !Sync for Reply
impl Unpin for Reply
impl !UnwindSafe for Reply
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more