Struct mini_server::HTTPServer
source · pub struct HTTPServer {
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 HTTPServer
impl HTTPServer
pub fn new(addr: &'static str, port: u32) -> Self
pub fn connect(&mut self, path: &'static str, handler: RequestHandler)
pub fn delete(&mut self, path: &'static str, handler: RequestHandler)
pub fn get(&mut self, path: &'static str, handler: RequestHandler)
pub fn head(&mut self, path: &'static str, handler: RequestHandler)
pub fn options(&mut self, path: &'static str, handler: RequestHandler)
pub fn patch(&mut self, path: &'static str, handler: RequestHandler)
pub fn post(&mut self, path: &'static str, handler: RequestHandler)
pub fn put(&mut self, path: &'static str, handler: RequestHandler)
pub fn trace(&mut self, path: &'static str, handler: RequestHandler)
pub fn on_any(&mut self, handler: EventHandler)
Trait Implementations§
source§impl Clone for HTTPServer
impl Clone for HTTPServer
source§fn clone(&self) -> HTTPServer
fn clone(&self) -> HTTPServer
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Server<&mut TcpStream, HTTPRequest> for HTTPServer
impl Server<&mut TcpStream, HTTPRequest> for HTTPServer
fn on_ready(&mut self, handler: SoftEventHandler)
fn on_shutdown(&mut self, handler: SoftEventHandler)
fn handle_request(&mut self, stream: &mut TcpStream, req: HTTPRequest)
fn run(&mut self)
Auto Trait Implementations§
impl Freeze for HTTPServer
impl RefUnwindSafe for HTTPServer
impl Send for HTTPServer
impl Sync for HTTPServer
impl Unpin for HTTPServer
impl UnwindSafe 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