Struct Request

Source
pub struct Request { /* private fields */ }
Expand description

A request containing data from the client.

Implementations§

Source§

impl Request

Source

pub fn new( resource: String, method: Method, id: Option<String>, data: JsonObject, params: JsonObject, ) -> Request

Source

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}
Source

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
Hide additional 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}
Source

pub fn resource(&self) -> &str

Source

pub fn id(&self) -> &Option<String>

Source

pub fn params(&self) -> &JsonObject

Source

pub fn params_mut(&mut self) -> &mut JsonObject

Source

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}
Source

pub fn set_param(&mut self, key: String, val: JsonValue)

Source

pub fn data(&self) -> &JsonObject

Source

pub fn data_mut(&mut self) -> &mut JsonObject

Source

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}
Source

pub fn and_then<F, B>(self, f: F) -> AndThen<FutureResult<Request, Error>, B, F>
where F: FnOnce(Request) -> B, B: IntoFuture<Error = Error>,

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
Hide additional 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 Debug for Request

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl IntoFuture for Request

Source§

type Item = Request

The item that the future may resolve with.
Source§

type Error = Error

The error that the future may resolve with.
Source§

type Future = FutureResult<Request, Error>

The future that this type can be converted into.
Source§

fn into_future(self) -> Self::Future

Consumes this object and produces a future.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.