[−][src]Struct shs::Server
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]
&mut self,
route: &str,
handler: &'static Handler<T>
) -> Result<(), Error>
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,
T: Send + Sync,
impl<T> Sync for Server<T> where
T: Send + Sync,
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]
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>,