pub struct Request { /* private fields */ }
Expand description
A request containing data from the client.
Implementations§
Source§impl Request
impl Request
pub fn new( resource: String, method: Method, id: Option<String>, data: JsonObject, params: JsonObject, ) -> Request
Sourcepub fn into_reply(self, reply: JsonObject) -> Reply
pub fn into_reply(self, reply: JsonObject) -> Reply
Examples found in repository?
examples/hello.rs (line 17)
7fn main() {
8 let mut s = Server::new();
9 s.resource("/meow", |_req: Request| {
10 Error::forbidden("not allowed! sorry.")
11 });
12 let adapter = Arc::new(memory::MemoryAdapter::new());
13 let channel = Arc::new(memory::MemoryChannel::new());
14 s.resource("/hello2", move |req: Request| {
15 req
16 .and_then(|req| {
17 req.into_reply(JsonObject::new())
18 })
19 });
20 s.resource("/hello", move |req: Request| {
21 let adapter = adapter.clone();
22 let channel1 = channel.clone();
23 // let channel2 = channel.clone();
24 req
25 .and_then(move |req| {
26 match req.method().clone() {
27 Method::Action(_) => Error::forbidden("not allowed! sorry."),
28 Method::Listen => channel1.handle(req),
29 _ => adapter.handle(req),
30 }
31 })
32 // .and_then(move |reply| { util::send_from_reply(reply, channel2.deref()) })
33 });
34 s.listen("127.0.0.1:3000");
35}
Sourcepub fn method(&self) -> Method
pub fn method(&self) -> Method
Examples found in repository?
examples/7.rs (line 20)
8fn main() {
9 let mut server = Server::new();
10 use std::sync::Arc;
11 use std::ops::Deref;
12 let database = Arc::new(memory::MemoryAdapter::new());
13 let chan = Arc::new(memory::MemoryChannel::new());
14 server.resource("/cats", move |req: Request| {
15 let database1 = database.clone();
16 let chan1 = chan.clone();
17 let chan2 = chan.clone();
18 req
19 .and_then(move |req| {
20 match req.method() {
21 Method::Listen => chan1.handle(req),
22 _ => database1.handle(req),
23 }
24 })
25 .and_then(move |reply| {
26 util::send_from_reply(reply, chan2.deref())
27 })
28 });
29 server.listen("127.0.0.1:3000");
30}
More examples
examples/6.rs (line 16)
8fn main() {
9 let mut server = Server::new();
10 use std::sync::Arc;
11 let database = Arc::new(memory::MemoryAdapter::new());
12 server.resource("/cats", move |req: Request| {
13 let database1 = database.clone();
14 req
15 .and_then(move |req| {
16 if req.method() == Method::Delete {
17 if let &JsonValue::String(ref password) = req.param("password") {
18 if password != "meow" {
19 return Error::forbidden("incorrect password");
20 }
21 } else {
22 return Error::unauthorized("please provide a password");
23 }
24 }
25 req.boxed()
26 })
27 .and_then(move |req| {
28 database1.handle(req)
29 })
30 });
31 server.listen("127.0.0.1:3000");
32}
examples/hello.rs (line 26)
7fn main() {
8 let mut s = Server::new();
9 s.resource("/meow", |_req: Request| {
10 Error::forbidden("not allowed! sorry.")
11 });
12 let adapter = Arc::new(memory::MemoryAdapter::new());
13 let channel = Arc::new(memory::MemoryChannel::new());
14 s.resource("/hello2", move |req: Request| {
15 req
16 .and_then(|req| {
17 req.into_reply(JsonObject::new())
18 })
19 });
20 s.resource("/hello", move |req: Request| {
21 let adapter = adapter.clone();
22 let channel1 = channel.clone();
23 // let channel2 = channel.clone();
24 req
25 .and_then(move |req| {
26 match req.method().clone() {
27 Method::Action(_) => Error::forbidden("not allowed! sorry."),
28 Method::Listen => channel1.handle(req),
29 _ => adapter.handle(req),
30 }
31 })
32 // .and_then(move |reply| { util::send_from_reply(reply, channel2.deref()) })
33 });
34 s.listen("127.0.0.1:3000");
35}
pub fn resource(&self) -> &str
pub fn id(&self) -> &Option<String>
pub fn params(&self) -> &JsonObject
pub fn params_mut(&mut self) -> &mut JsonObject
Sourcepub fn param(&self, key: &str) -> &JsonValue
pub fn param(&self, key: &str) -> &JsonValue
Examples found in repository?
examples/6.rs (line 17)
8fn main() {
9 let mut server = Server::new();
10 use std::sync::Arc;
11 let database = Arc::new(memory::MemoryAdapter::new());
12 server.resource("/cats", move |req: Request| {
13 let database1 = database.clone();
14 req
15 .and_then(move |req| {
16 if req.method() == Method::Delete {
17 if let &JsonValue::String(ref password) = req.param("password") {
18 if password != "meow" {
19 return Error::forbidden("incorrect password");
20 }
21 } else {
22 return Error::unauthorized("please provide a password");
23 }
24 }
25 req.boxed()
26 })
27 .and_then(move |req| {
28 database1.handle(req)
29 })
30 });
31 server.listen("127.0.0.1:3000");
32}
pub fn set_param(&mut self, key: String, val: JsonValue)
pub fn data(&self) -> &JsonObject
pub fn data_mut(&mut self) -> &mut JsonObject
Sourcepub fn boxed(self) -> BoxFuture<Request, Error>
pub fn boxed(self) -> BoxFuture<Request, Error>
Examples found in repository?
examples/6.rs (line 25)
8fn main() {
9 let mut server = Server::new();
10 use std::sync::Arc;
11 let database = Arc::new(memory::MemoryAdapter::new());
12 server.resource("/cats", move |req: Request| {
13 let database1 = database.clone();
14 req
15 .and_then(move |req| {
16 if req.method() == Method::Delete {
17 if let &JsonValue::String(ref password) = req.param("password") {
18 if password != "meow" {
19 return Error::forbidden("incorrect password");
20 }
21 } else {
22 return Error::unauthorized("please provide a password");
23 }
24 }
25 req.boxed()
26 })
27 .and_then(move |req| {
28 database1.handle(req)
29 })
30 });
31 server.listen("127.0.0.1:3000");
32}
Sourcepub fn and_then<F, B>(self, f: F) -> AndThen<FutureResult<Request, Error>, B, F>
pub fn and_then<F, B>(self, f: F) -> AndThen<FutureResult<Request, Error>, B, F>
Examples found in repository?
examples/5.rs (lines 15-17)
8fn main() {
9 let mut server = Server::new();
10 use std::sync::Arc;
11 let database = Arc::new(memory::MemoryAdapter::new());
12 server.resource("/cats", move |req: Request| {
13 let database1 = database.clone();
14 req
15 .and_then(move |req| {
16 database1.handle(req)
17 })
18 });
19 server.listen("127.0.0.1:3000");
20}
More examples
examples/7.rs (lines 19-24)
8fn main() {
9 let mut server = Server::new();
10 use std::sync::Arc;
11 use std::ops::Deref;
12 let database = Arc::new(memory::MemoryAdapter::new());
13 let chan = Arc::new(memory::MemoryChannel::new());
14 server.resource("/cats", move |req: Request| {
15 let database1 = database.clone();
16 let chan1 = chan.clone();
17 let chan2 = chan.clone();
18 req
19 .and_then(move |req| {
20 match req.method() {
21 Method::Listen => chan1.handle(req),
22 _ => database1.handle(req),
23 }
24 })
25 .and_then(move |reply| {
26 util::send_from_reply(reply, chan2.deref())
27 })
28 });
29 server.listen("127.0.0.1:3000");
30}
examples/6.rs (lines 15-26)
8fn main() {
9 let mut server = Server::new();
10 use std::sync::Arc;
11 let database = Arc::new(memory::MemoryAdapter::new());
12 server.resource("/cats", move |req: Request| {
13 let database1 = database.clone();
14 req
15 .and_then(move |req| {
16 if req.method() == Method::Delete {
17 if let &JsonValue::String(ref password) = req.param("password") {
18 if password != "meow" {
19 return Error::forbidden("incorrect password");
20 }
21 } else {
22 return Error::unauthorized("please provide a password");
23 }
24 }
25 req.boxed()
26 })
27 .and_then(move |req| {
28 database1.handle(req)
29 })
30 });
31 server.listen("127.0.0.1:3000");
32}
examples/hello.rs (lines 16-18)
7fn main() {
8 let mut s = Server::new();
9 s.resource("/meow", |_req: Request| {
10 Error::forbidden("not allowed! sorry.")
11 });
12 let adapter = Arc::new(memory::MemoryAdapter::new());
13 let channel = Arc::new(memory::MemoryChannel::new());
14 s.resource("/hello2", move |req: Request| {
15 req
16 .and_then(|req| {
17 req.into_reply(JsonObject::new())
18 })
19 });
20 s.resource("/hello", move |req: Request| {
21 let adapter = adapter.clone();
22 let channel1 = channel.clone();
23 // let channel2 = channel.clone();
24 req
25 .and_then(move |req| {
26 match req.method().clone() {
27 Method::Action(_) => Error::forbidden("not allowed! sorry."),
28 Method::Listen => channel1.handle(req),
29 _ => adapter.handle(req),
30 }
31 })
32 // .and_then(move |reply| { util::send_from_reply(reply, channel2.deref()) })
33 });
34 s.listen("127.0.0.1:3000");
35}
Trait Implementations§
Source§impl IntoFuture for Request
impl IntoFuture for Request
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 Request
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnwindSafe for Request
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