[][src]Struct web_server::HttpServer

pub struct HttpServer { /* fields omitted */ }

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]

Add a route for a specific path and method

pub fn get(
    self,
    path: &'static str,
    handler: fn(_: Request, _: Response) -> Response
) -> Self
[src]

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]

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]

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) -> ![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 Debug for HttpServer[src]

impl Default for HttpServer[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.