pub struct WebServer { /* private fields */ }Expand description
Main web server struct that uses an adapter
Implementations§
Source§impl WebServer
impl WebServer
Sourcepub fn with_mock_adapter() -> Self
pub fn with_mock_adapter() -> Self
Create a new web server with the mock adapter
Sourcepub fn with_axum_adapter() -> Self
pub fn with_axum_adapter() -> Self
Create a new web server with the Axum adapter
Sourcepub fn route<H, T>(
self,
path: impl Into<String>,
method: HttpMethod,
handler: H,
) -> Selfwhere
H: Handler<T>,
pub fn route<H, T>(
self,
path: impl Into<String>,
method: HttpMethod,
handler: H,
) -> Selfwhere
H: Handler<T>,
Add a route to the server
Sourcepub fn middleware<M>(self, middleware: M) -> Selfwhere
M: Middleware + 'static,
pub fn middleware<M>(self, middleware: M) -> Selfwhere
M: Middleware + 'static,
Add middleware to the server
Sourcepub fn with_path_params(self) -> Self
pub fn with_path_params(self) -> Self
Enable automatic path parameter extraction This adds middleware that automatically extracts path parameters from routes and makes them available via req.param()
Sourcepub fn websocket(self, path: impl Into<String>) -> Self
pub fn websocket(self, path: impl Into<String>) -> Self
Add a WebSocket route to the server Note: This is a basic implementation. Full WebSocket support requires framework-specific handling in each adapter.
Sourcepub fn get<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
pub fn get<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
Convenience method for GET routes
Sourcepub fn post<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
pub fn post<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
Convenience method for POST routes
Sourcepub fn put<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
pub fn put<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
Convenience method for PUT routes
Sourcepub fn delete<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
pub fn delete<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
Convenience method for DELETE routes
Sourcepub fn patch<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
pub fn patch<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
Convenience method for PATCH routes
Sourcepub fn head<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
pub fn head<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
Convenience method for HEAD routes
Sourcepub fn options<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
pub fn options<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
Convenience method for OPTIONS routes
Sourcepub fn trace<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
pub fn trace<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
Convenience method for TRACE routes
Sourcepub fn connect<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
pub fn connect<H, T>(self, path: impl Into<String>, handler: H) -> Selfwhere
H: Handler<T>,
Convenience method for CONNECT routes
Sourcepub fn param_route<H, T>(
self,
path: impl Into<String>,
method: HttpMethod,
handler: H,
) -> Selfwhere
H: Handler<T>,
pub fn param_route<H, T>(
self,
path: impl Into<String>,
method: HttpMethod,
handler: H,
) -> Selfwhere
H: Handler<T>,
Add a route with path parameters (e.g., “/users/:id”)
Sourcepub fn wildcard_route<H, T>(
self,
path: impl Into<String>,
method: HttpMethod,
handler: H,
) -> Selfwhere
H: Handler<T>,
pub fn wildcard_route<H, T>(
self,
path: impl Into<String>,
method: HttpMethod,
handler: H,
) -> Selfwhere
H: Handler<T>,
Add a wildcard route (e.g., “/static/*file”)
Sourcepub async fn bind(self, addr: &str) -> Result<BoundServer>
pub async fn bind(self, addr: &str) -> Result<BoundServer>
Bind the server to an address
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WebServer
impl !RefUnwindSafe for WebServer
impl Send for WebServer
impl Sync for WebServer
impl Unpin for WebServer
impl !UnwindSafe for WebServer
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more