pub struct HTTPServer {
pub addr: Vec<SocketAddr>,
pub paths: Vec<Path>,
pub listeners: Vec<Listener>,
pub on_ready: Option<SoftListener>,
pub on_shutdown: Option<SoftListener>,
pub on_error: Option<ErrorListener>,
pub thread_pool: ThreadPool,
pub should_shutdown: ShutdownWrapper,
}Expand description
This struct provide a simple http server that handle many of the use cases
§Example
use mini_server::*;
let mut app = HTTPServer::default();
app.get("/", |_, _| {
"Hello World!".into()
});
§Path
The path is an expression that can contains dynamic variables.
- Basic paths:
/,/this/is/a/path, … - Dynamic path:
/this/is/a/@varibale,/this/is/another/#variable
# and @ are prefixes for dynamic values. # for denoting numbers
and @ for strings. float can start with a dot (.)
Fields§
§addr: Vec<SocketAddr>§paths: Vec<Path>§listeners: Vec<Listener>§on_ready: Option<SoftListener>§on_shutdown: Option<SoftListener>§on_error: Option<ErrorListener>§thread_pool: ThreadPool§should_shutdown: ShutdownWrapperImplementations§
Source§impl HTTPServer
impl HTTPServer
pub fn get<T>(&mut self, path: &'static str, handler: T)
pub fn post<T>(&mut self, path: &'static str, handler: T)
pub fn put<T>(&mut self, path: &'static str, handler: T)
pub fn delete<T>(&mut self, path: &'static str, handler: T)
pub fn patch<T>(&mut self, path: &'static str, handler: T)
pub fn options<T>(&mut self, path: &'static str, handler: T)
pub fn head<T>(&mut self, path: &'static str, handler: T)
pub fn trace<T>(&mut self, path: &'static str, handler: T)
pub fn connect<T>(&mut self, path: &'static str, handler: T)
Trait Implementations§
Source§impl Clone for HTTPServer
impl Clone for HTTPServer
Source§impl Default for HTTPServer
impl Default for HTTPServer
Source§impl Server<&mut TcpStream, HTTPRequest> for HTTPServer
impl Server<&mut TcpStream, HTTPRequest> for HTTPServer
fn handle_request(&self, stream: &mut TcpStream, req: HTTPRequest)
fn run(&self)
Auto Trait Implementations§
impl !Freeze for HTTPServer
impl !RefUnwindSafe for HTTPServer
impl !UnwindSafe for HTTPServer
impl Send for HTTPServer
impl Sync for HTTPServer
impl Unpin for HTTPServer
impl UnsafeUnpin for HTTPServer
Blanket Implementations§
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
Mutably borrows from an owned value. Read more