[][src]Struct shs::Server

pub struct Server<T> { /* fields omitted */ }

HTTP 1.1 server.

Example usage:

use anyhow::Error;
use fehler::throws;
use shs::{Request, Server};

#[throws]
fn handler(req: &mut Request<()>) {
    todo!();
}

let mut server = Server::new("127.0.0.1:1234", ())?;
server.route("GET /hello", &handler)?;
server.launch()?;

Implementations

impl<T: Send + Sync + 'static> Server<T>[src]

pub fn new(address: &str, state: T) -> Result<Server<T>, Error>[src]

Create a new Server.

pub fn route(
    &mut self,
    route: &str,
    handler: &'static Handler<T>
) -> Result<(), Error>
[src]

Add a new route. The basic format is "METHOD /path". The path can contain parameters that start with a colon, for example "/resource/:key"; these parameters act as wild cards that can match any single path segment.

pub fn state(&self) -> Arc<RwLock<T>>[src]

Get the shared application state.

This is useful if you are spawning additional worker threads that will also use this state.

pub fn launch(self) -> Result<(), Error>[src]

Start the server.

pub fn test_request(&self, input: &TestRequest) -> Result<TestResponse, Error>[src]

Send a fake request for testing.

Auto Trait Implementations

impl<T> RefUnwindSafe for Server<T>

impl<T> Send for Server<T> where
    T: Send + Sync

impl<T> Sync for Server<T> where
    T: Send + Sync

impl<T> Unpin for Server<T>

impl<T> UnwindSafe for Server<T>

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.