Struct arc_reactor::core::Request [−][src]
pub struct Request { /* fields omitted */ }
Methods
impl Request
[src]
impl Request
pub fn version(&self) -> &Version
[src]
pub fn version(&self) -> &Version
Returns a reference to the request's Version
pub fn headers(&self) -> &HeaderMap<HeaderValue>
[src]
pub fn headers(&self) -> &HeaderMap<HeaderValue>
Returns a reference to the request's headers
pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
[src]
pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
pub fn method(&self) -> &Method
[src]
pub fn method(&self) -> &Method
Returns a reference to the request's method
The methods can be any of the following: GET, HEAD, POST, PUT DELETE, CONNECT, OPTIONS, TRACE, PATCH.
pub fn uri(&self) -> &Uri
[src]
pub fn uri(&self) -> &Uri
Returns a request to the request's Uri
pub fn path(&self) -> &str
[src]
pub fn path(&self) -> &str
Returns the query path of the request.
pub fn remote_ip(&self) -> Option<SocketAddr>
[src]
pub fn remote_ip(&self) -> Option<SocketAddr>
Returns the IP of the connected client.
This should always be set, except in testing environments with
FakeReactor
.
pub fn query<T>(&self) -> Result<T, QueryParseError> where
T: DeserializeOwned,
[src]
pub fn query<T>(&self) -> Result<T, QueryParseError> where
T: DeserializeOwned,
Serializes the query string into a struct via serde.
Examples
extern crate serde; #[macro_use] extern crate serde_derive; extern crate arc_reactor; use arc_reactor::prelude::*; #[derive(Serialize, Deserialize)] struct AccessToken { token: String, } #[service] pub fn login(req: Request, _res: Response) { if let Ok(AccessToken { token }) = req.query() { // do something with the token here. } }
pub fn params(&self) -> Option<&Params>
[src]
pub fn params(&self) -> Option<&Params>
Get the url params for the request.
e.g /profile/:id
extern crate arc_reactor; use arc_reactor::prelude::*; [service] pub fn ProfileService(req: Request, res: Response) { let profileId = req.params().unwrap()["id"]; // Its safe to unwrap here as this woute would never be matched without the `id` }
pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>
[src]
pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>
The request struct constains an AnyMap
so that middlewares can append
additional information.
You can get values out of the AnyMap
by using this method.
Examples
extern crate arc_reactor; use arc_reactor::prelude::*; #[derive(Serialize, Deserialize)] struct AccessToken { token: String, } struct User { name: String, } #[middleware(Request)] pub fn AssertAuth(req: Request) { if let AccessToken { token } = req.query::<AccessToken>() { let user = User { name: "Seun" }; req.set::<User>(user); // Set the user } else { return Err((401, "Unauthorized!").into()); } } #[service] pub fn ProfileService(req: Request, res: Response) { let user = req.get::<User>().unwrap(); // Its safe to unwrap here, because if user isn't set this service will never // be called. }
pub fn set<T: Send + Sync + 'static>(&mut self, value: T) -> Option<T>
[src]
pub fn set<T: Send + Sync + 'static>(&mut self, value: T) -> Option<T>
Set a type on the request.
pub fn remove<T: Send + Sync + 'static>(&mut self) -> Option<T>
[src]
pub fn remove<T: Send + Sync + 'static>(&mut self) -> Option<T>
Removes the type previously set on the request.
pub fn body(&mut self) -> Body
[src]
pub fn body(&mut self) -> Body
Move the request body
pub fn json<T>(&self) -> Result<T, JsonError> where
T: DeserializeOwned,
[src]
pub fn json<T>(&self) -> Result<T, JsonError> where
T: DeserializeOwned,
Serialize the request's json value into a struct.
Note that the json value needs to have been previously set on the
request by a middleware; otherwise this would return
Err(JsonError::None)
.
pub fn body_ref(&self) -> &Body
[src]
pub fn body_ref(&self) -> &Body
Get a reference to the request body.
pub fn body_mut(&mut self) -> &mut Body
[src]
pub fn body_mut(&mut self) -> &mut Body
Get a reference to the request body.
pub fn set_body(&mut self, body: Body)
[src]
pub fn set_body(&mut self, body: Body)
Set the request body.
Trait Implementations
impl From<Request<Body>> for Request
[src]
impl From<Request<Body>> for Request
impl<T> MiddleWare<Request> for T where
T: Fn(Request) -> MiddleWareFuture<Request> + Send + Sync + Clone + 'static,
[src]
impl<T> MiddleWare<Request> for T where
T: Fn(Request) -> MiddleWareFuture<Request> + Send + Sync + Clone + 'static,
fn call(&self, req: Request) -> MiddleWareFuture<Request>
[src]
fn call(&self, req: Request) -> MiddleWareFuture<Request>
impl MiddleWare<Request> for Vec<Box<MiddleWare<Request>>>
[src]
impl MiddleWare<Request> for Vec<Box<MiddleWare<Request>>>
This enables a vector of MiddleWare<Request>
to behave like a single
MiddleWare<Request>
returning Err(Response)
in any of the
MiddleWare<Request>
will cause the rest of the middlewares to be skipped.
Note that there's a conveinience macro mw
that allows you not write boxes
everywhere.
fn call(&self, request: Request) -> MiddleWareFuture<Request>
[src]
fn call(&self, request: Request) -> MiddleWareFuture<Request>
impl MiddleWare<Request> for Box<MiddleWare<Request>>
[src]
impl MiddleWare<Request> for Box<MiddleWare<Request>>
fn call(&self, item: Request) -> MiddleWareFuture<Request>
[src]
fn call(&self, item: Request) -> MiddleWareFuture<Request>
impl MiddleWare<Request> for BodyParser
[src]
impl MiddleWare<Request> for BodyParser
fn call(&self, req: Request) -> MiddleWareFuture<Request>
[src]
fn call(&self, req: Request) -> MiddleWareFuture<Request>
impl MiddleWare<Request> for StaticFileServer
[src]
impl MiddleWare<Request> for StaticFileServer
fn call(&self, req: Request) -> MiddleWareFuture<Request>
[src]
fn call(&self, req: Request) -> MiddleWareFuture<Request>
impl Debug for Request
[src]
impl Debug for Request