[−][src]Struct web_server::HttpServer
Storing basics informations about server and handlers Represents http server
Methods
impl HttpServer
[src]
pub fn new() -> Self
[src]
Create new instance of HttpServer
pub fn route(
self,
method: HttpMethod,
path: &'static str,
handler: fn(_: Request, _: Response) -> Response
) -> Self
[src]
self,
method: HttpMethod,
path: &'static str,
handler: fn(_: Request, _: Response) -> Response
) -> Self
Add a route for a specific path and method
pub fn get(
self,
path: &'static str,
handler: fn(_: Request, _: Response) -> Response
) -> Self
[src]
self,
path: &'static str,
handler: fn(_: Request, _: Response) -> Response
) -> Self
Add a route for GET method and a specific path
server.get("/user/:id", |request, _| { database.get_user(request.params.get("id").unwrap()).into() })
pub fn post(
self,
path: &'static str,
handler: fn(_: Request, _: Response) -> Response
) -> Self
[src]
self,
path: &'static str,
handler: fn(_: Request, _: Response) -> Response
) -> Self
Add a route for POST method and a specific path
server.post("/add-user", |request, mut default_response| { println!("Save new user!\n\n{}", request.get_body()); default_response.headers.insert("Access-Control-Allow-Origin", "*"); default_repsonse })
pub fn any(
self,
path: &'static str,
handler: fn(_: Request, _: Response) -> Response
) -> Self
[src]
self,
path: &'static str,
handler: fn(_: Request, _: Response) -> Response
) -> Self
Add a route for a specific path and any method
server .get("/endpoint", |request, default_response| "Gate GET were obtained".into()) .post("/endpoint", |request, default_response| "Gate POST were obtained".into()) .any("/endpoint", |request, default_response| "Another gate were obtained".into())
pub fn not_found(self, handler: fn(_: Request, _: Response) -> Response) -> Self
[src]
Add a handler for 404 error
server.not_found(|_, _| "Not found!".into());
impl HttpServer
[src]
pub fn run(self) -> Result<()>
[src]
Launch server on port 80
pub fn launch(self, port: i32) -> Result<()>
[src]
Lauch http server, never returns
server.launch(8080).unwrap();
Trait Implementations
impl Default for HttpServer
[src]
impl Debug for HttpServer
[src]
Auto Trait Implementations
impl Send for HttpServer
impl Unpin for HttpServer
impl Sync for HttpServer
impl RefUnwindSafe for HttpServer
impl UnwindSafe for HttpServer
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,