pub struct App<T> { /* private fields */ }
Expand description
Express app
Implementations§
Source§impl<T: Send + Sync + 'static> App<T>
impl<T: Send + Sync + 'static> App<T>
Sourcepub fn new() -> App<T>
pub fn new() -> App<T>
Create a new App The app can later be configured with middleware, routers and handlers.
Sourcepub async fn listen(self, port: u16) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn listen(self, port: u16) -> Result<(), Box<dyn Error + Send + Sync>>
Binds the app to the given port
§Examples
use rs_express::App;
type Locals = ();
#[tokio::main]
async fn main() {
let mut app: App<Locals>= App::new();
app.listen(0).await.expect("Failed to listen");
}
pub fn set_locals(&mut self, locals: T) -> &mut Self
pub fn router(&mut self, router: Router<T>) -> &mut Self
Sourcepub fn use_ok<F>(&mut self, handler: F) -> &mut Self
pub fn use_ok<F>(&mut self, handler: F) -> &mut Self
Adds a new middleware that apply to every request received.
Sourcepub fn get<F>(&mut self, path: &'static str, handler: F) -> &mut Self
pub fn get<F>(&mut self, path: &'static str, handler: F) -> &mut Self
Adds a new middleware that apply to every GET request received.
Sourcepub fn post<F>(&mut self, path: &'static str, handler: F) -> &mut Self
pub fn post<F>(&mut self, path: &'static str, handler: F) -> &mut Self
Adds a new middleware that apply to every POST request received.
Sourcepub fn put<F>(&mut self, path: &'static str, handler: F) -> &mut Self
pub fn put<F>(&mut self, path: &'static str, handler: F) -> &mut Self
Adds a new middleware that apply to every PUT request received.
Sourcepub fn patch<F>(&mut self, path: &'static str, handler: F) -> &mut Self
pub fn patch<F>(&mut self, path: &'static str, handler: F) -> &mut Self
Adds a new middleware that apply to every PATCH request received.
Auto Trait Implementations§
impl<T> Freeze for App<T>where
T: Freeze,
impl<T> !RefUnwindSafe for App<T>
impl<T> Send for App<T>where
T: Send,
impl<T> Sync for App<T>where
T: Sync,
impl<T> Unpin for App<T>where
T: Unpin,
impl<T> !UnwindSafe for App<T>
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