Struct mini_server::HTTPServer
source · pub struct HTTPServer<'a> {
pub addr: &'static str,
pub port: u32,
/* private fields */
}
Expand description
This struct provide a simple http server that handle many of the use cases
§Example
use mini_server::*;
let mut app = http_server!("localhost", 4221);
app.get("/", |_, _| {
let mut response = HTTPResponse::default();
response.set_body(b"Hello World!".to_vec());
response
});
§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
Fields§
§addr: &'static str
§port: u32
Implementations§
source§impl<'a> HTTPServer<'a>
impl<'a> HTTPServer<'a>
pub fn new(addr: &'static str, port: u32) -> Self
pub fn on_ready<T>(&mut self, handler: T)where
T: Fn() + 'a,
pub fn on_shutdown<T>(&mut self, handler: T)where
T: Fn() + 'a,
pub fn connect<T>(&mut self, path: &'static str, handler: T)
pub fn delete<T>(&mut self, path: &'static str, handler: T)
pub fn get<T>(&mut self, path: &'static str, handler: T)
pub fn head<T>(&mut self, path: &'static str, handler: T)
pub fn options<T>(&mut self, path: &'static str, handler: T)
pub fn patch<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 trace<T>(&mut self, path: &'static str, handler: T)
pub fn on_any<T>(&mut self, handler: T)
Trait Implementations§
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<'a> Freeze for HTTPServer<'a>
impl<'a> !RefUnwindSafe for HTTPServer<'a>
impl<'a> !Send for HTTPServer<'a>
impl<'a> !Sync for HTTPServer<'a>
impl<'a> Unpin for HTTPServer<'a>
impl<'a> !UnwindSafe for HTTPServer<'a>
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