[−][src]Struct rusty_express::prelude::HttpServer
The server instance that represents and controls the underlying http-service.
Methods
impl HttpServer
[src]
pub fn new() -> Self
[src]
Create a new server instance using default configurations and server settings.
pub fn new_with_config(config: ServerConfig) -> Self
[src]
Create a new server instance with supplied configuration and settings.
pub fn listen(&mut self, port: u16)
[src]
listen
will take 1 parameter for the port that the server will be monitoring at, aka
127.0.0.1:port
. This function will block until the server is shut down.
Examples
extern crate rusty_express as express; use express::prelude::{HttpServer, ServerDef, Router, Route}; let mut server = HttpServer::new(); let mut router = Route::new(); // ... code to add router handlers to ... server.def_router(router); server.listen(8080);
pub fn listen_and_serve(
&mut self,
port: u16,
callback: Option<fn(_: AsyncController)>
)
[src]
&mut self,
port: u16,
callback: Option<fn(_: AsyncController)>
)
listen_and_serve
will take 2 parameters: 1) the port that the server will be monitoring at,
or 127.0.0.1:port
; 2) the callback closure that will take an async-controller as input,
and run in parallel to the current server instance for async operations.
This function will block until the server is shut down.
Examples
extern crate rusty_express as express; use express::prelude::{HttpServer, ServerDef, Router, Route, ControlMessage}; use std::thread; use std::time::Duration; let mut server = HttpServer::new(); let mut router = Route::new(); // ... code to add router handlers to ... server.def_router(router); server.listen_and_serve(8080, |controller| { // sleep for 1 minute thread::sleep(Duration::from_secs(60)); // after waking up from the 1 minute sleep, shut down the server. controller.send(ControlMessage::Terminate); });
#[must_use]
pub fn get_courier(&self) -> AsyncController
[src]
Obtain an AsyncController
, which can be run in a parallel thread and control or update
server configurations while it's running. For more details, see the states
module.
pub fn drop_session_auto_clean(&mut self)
[src]
Stop and clear the session auto-cleaning schedules. This API can be useful when no more new sessions shall be built and stored in the server, to save server resources.
pub fn config(&mut self) -> &mut ServerConfig
[src]
Obtain a reference to the server config, such that we can make updates before launching the server but without creating the config struct and pass it in on building the server.
pub fn config_hot_reload(&self)
[src]
Ask the server to reload the configuration settings. Usually used in a separate thread with a cloned server instance, where the server state is corrupted and need a reload to restore the initial server settings.
Trait Implementations
impl ViewEngineDefinition for HttpServer
[src]
fn view_engine(extension: &str, engine: ViewEngine)
[src]
impl Router for HttpServer
[src]
fn get(
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
[src]
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
fn patch(
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
[src]
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
fn post(
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
[src]
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
fn put(
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
[src]
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
fn delete(
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
[src]
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
fn options(
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
[src]
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
fn other(
&mut self,
method: &str,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
[src]
&mut self,
method: &str,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
fn all(
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
[src]
&mut self,
uri: RequestPath,
callback: fn(_: &Box<Request>, _: &mut Box<Response>)
) -> &mut dyn Router
fn use_static(&mut self, path: PathBuf) -> &mut dyn Router
[src]
Example
extern crate rusty_express; use rusty_express::prelude::*; use std::path::PathBuf; fn main() { // define http server now let mut server = HttpServer::new(); server.set_pool_size(8); server.use_static(PathBuf::from(r".\static")); }
fn use_custom_static(
&mut self,
uri: RequestPath,
path: PathBuf
) -> &mut dyn Router
[src]
&mut self,
uri: RequestPath,
path: PathBuf
) -> &mut dyn Router
fn case_sensitive(&mut self, allow_case: bool, method: Option<REST>)
[src]
impl ServerDef for HttpServer
[src]
fn def_router(&mut self, router: Route)
[src]
Replace the default server router with the pre-built one. This is a wrapper over
Route::use_router
, which will achieve same goal.
fn set_pool_size(&mut self, size: usize)
[src]
Set the pool size. Note that this API is only functional before launching the server. After
the server has started and been running, set_pool_size
will be no-op.
fn set_read_timeout(&mut self, timeout: u16)
[src]
Set the read timeout for the handler. If no more incoming data stream are detected on the socket, the read stream will be closed.
fn set_write_timeout(&mut self, timeout: u16)
[src]
Set the write timeout for the handler. If no more outgoing data stream are detected on the socket, the write stream will be closed.
fn def_default_response_header(&mut self, header: HashMap<String, String>)
[src]
Define headers and their contents that shall go along with every http response. This will remove any existing default headers and corresponding contents.
fn set_default_response_header(&mut self, field: String, value: String)
[src]
Set or update default headers and their contents that shall go along with every http response. If a default header with same name exists, the new contents will replace the existing one.
fn enable_session_auto_clean(&mut self, auto_clean_period: Duration)
[src]
If using the session
feature, this API will automatically purge stale session stores, such
that we can reclaim resources that's no longer in use.
fn disable_session_auto_clean(&mut self)
[src]
If using the session
feature, this API will turn off the periodic session store clean up
impl Default for HttpServer
[src]
Auto Trait Implementations
impl Sync for HttpServer
impl Send for HttpServer
impl Unpin for HttpServer
impl !RefUnwindSafe for HttpServer
impl !UnwindSafe for HttpServer
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,