Struct HTTPServer

Source
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

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: ShutdownWrapper

Implementations§

Source§

impl HTTPServer

Source

pub fn get<T>(&mut self, path: &'static str, handler: T)
where T: Fn(HTTPRequest, PathMap) -> HTTPResponse + Send + Sync + 'static,

Source

pub fn post<T>(&mut self, path: &'static str, handler: T)
where T: Fn(HTTPRequest, PathMap) -> HTTPResponse + Send + Sync + 'static,

Source

pub fn put<T>(&mut self, path: &'static str, handler: T)
where T: Fn(HTTPRequest, PathMap) -> HTTPResponse + Send + Sync + 'static,

Source

pub fn delete<T>(&mut self, path: &'static str, handler: T)
where T: Fn(HTTPRequest, PathMap) -> HTTPResponse + Send + Sync + 'static,

Source

pub fn patch<T>(&mut self, path: &'static str, handler: T)
where T: Fn(HTTPRequest, PathMap) -> HTTPResponse + Send + Sync + 'static,

Source

pub fn options<T>(&mut self, path: &'static str, handler: T)
where T: Fn(HTTPRequest, PathMap) -> HTTPResponse + Send + Sync + 'static,

Source

pub fn head<T>(&mut self, path: &'static str, handler: T)
where T: Fn(HTTPRequest, PathMap) -> HTTPResponse + Send + Sync + 'static,

Source

pub fn trace<T>(&mut self, path: &'static str, handler: T)
where T: Fn(HTTPRequest, PathMap) -> HTTPResponse + Send + Sync + 'static,

Source

pub fn connect<T>(&mut self, path: &'static str, handler: T)
where T: Fn(HTTPRequest, PathMap) -> HTTPResponse + Send + Sync + 'static,

Source§

impl HTTPServer

Source

pub fn new<A>(addr: A) -> Self
where A: ToSocketAddrs,

Source

pub fn on_ready<T>(&mut self, handler: T)
where T: Fn() + Send + Sync + 'static,

Source

pub fn shutdown(&self)

Source

pub fn on_shutdown<T>(&mut self, handler: T)
where T: Fn() + Send + Sync + 'static,

Source

pub fn on_error<T>(&mut self, handler: T)
where T: Fn(RunError) + Send + Sync + 'static,

Source

pub fn on_any<T>(&mut self, handler: T)
where T: Fn(&HTTPRequest, &mut HTTPResponse) + Send + Sync + 'static,

Trait Implementations§

Source§

impl Clone for HTTPServer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for HTTPServer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Server<&mut TcpStream, HTTPRequest> for HTTPServer

Source§

fn handle_request(&self, stream: &mut TcpStream, req: HTTPRequest)

Source§

fn run(&self)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.