[−][src]Struct web_server::HttpServer
Storing basics informations about server and handlers Represents http server
Implementations
impl HttpServer
[src]
pub fn new() -> Self
[src]
Create new instance of HttpServer
pub fn route(
self,
method: HttpMethod,
path: &'static str,
handler: RequestHandler
) -> Self
[src]
self,
method: HttpMethod,
path: &'static str,
handler: RequestHandler
) -> Self
Add a route for a specific path and method
pub fn get(self, path: &'static str, handler: RequestHandler) -> Self
[src]
Add a route for GET method and a specific path
server.get("/user/:id", Box::new(|request, _| { database.get_user(request.params.get("id").unwrap()).into() }))
pub fn post(self, path: &'static str, handler: RequestHandler) -> Self
[src]
Add a route for POST method and a specific path
server.post("/add-user", Box::new(|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: RequestHandler) -> Self
[src]
Add a route for a specific path and any method
server .get("/endpoint", Box::new(|request, default_response| "Gate GET were obtained".into())) .post("/endpoint", Box::new(|request, default_response| "Gate POST were obtained".into())) .any("/endpoint", Box::new(|request, default_response| "Another gate were obtained".into()))
pub fn not_found(self, handler: RequestHandler) -> Self
[src]
Add a handler for 404 error
server.not_found(Box::new(|_, _| "Not found!".into()));
impl HttpServer
[src]
pub fn run(self) -> !
[src]
Launch server on port 80
pub fn launch(self, port: i32) -> !
[src]
Lauch http server, never returns
server.launch(8080).unwrap();
Trait Implementations
impl Default for HttpServer
[src]
Auto Trait Implementations
impl !RefUnwindSafe for HttpServer
impl Send for HttpServer
impl !Sync for HttpServer
impl Unpin for HttpServer
impl !UnwindSafe for HttpServer
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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>,