Struct Express

Source
pub struct Express { /* private fields */ }

Implementations§

Source§

impl Express

Main application object

Provides ways to mount path and method combinations and assign functions to them.

Source

pub fn new() -> Self

Examples found in repository?
examples/body.rs (line 6)
5fn main() {
6    let mut app = Express::new();
7    app.post("/", |req, res| {
8        if let Some(body) = &req.body {
9            res.send(body.to_string());
10        } else {
11            res.send("Nobody here...".to_string());
12        }
13    });
14
15    let port = 8080;
16    println!("Starting server on port {}", port);
17    app.listen(port);
18}
More examples
Hide additional examples
examples/get.rs (line 4)
3fn main() {
4    let mut app = Express::new();
5    app.get("/", |_, res| res.send("Hello World!".to_string()));
6    app.get("/hello", |_, res| {
7        res.send("<h1>Hi from /hello!</h1>".to_string())
8    });
9
10    app.get("/redirect", |_, res| {
11        res.status(301)
12            .send("This route has a redirect status code!".to_string())
13    });
14
15    app.listen(8080);
16}
Source

pub fn get<F>(&mut self, path: &str, callback: F) -> &mut Self
where F: FnMut(&Request, &mut Response) + 'static, Self: Sized,

Examples found in repository?
examples/get.rs (line 5)
3fn main() {
4    let mut app = Express::new();
5    app.get("/", |_, res| res.send("Hello World!".to_string()));
6    app.get("/hello", |_, res| {
7        res.send("<h1>Hi from /hello!</h1>".to_string())
8    });
9
10    app.get("/redirect", |_, res| {
11        res.status(301)
12            .send("This route has a redirect status code!".to_string())
13    });
14
15    app.listen(8080);
16}
Source

pub fn post<F>(&mut self, path: &str, callback: F) -> &mut Self
where F: FnMut(&Request, &mut Response) + 'static, Self: Sized,

Examples found in repository?
examples/body.rs (lines 7-13)
5fn main() {
6    let mut app = Express::new();
7    app.post("/", |req, res| {
8        if let Some(body) = &req.body {
9            res.send(body.to_string());
10        } else {
11            res.send("Nobody here...".to_string());
12        }
13    });
14
15    let port = 8080;
16    println!("Starting server on port {}", port);
17    app.listen(port);
18}
Source

pub fn put<F>(&mut self, path: &str, callback: F) -> &mut Self
where F: FnMut(&Request, &mut Response) + 'static, Self: Sized,

Source

pub fn delete<F>(&mut self, path: &str, callback: F) -> &mut Self
where F: FnMut(&Request, &mut Response) + 'static, Self: Sized,

Source

pub fn patch<F>(&mut self, path: &str, callback: F) -> &mut Self
where F: FnMut(&Request, &mut Response) + 'static, Self: Sized,

Source

pub fn listen(&mut self, port: u16)

Port numbers can range from 1-65535, therefore a u16 is used here

§Panics

Panics, if:

  • a port is not between 1-65535 or
  • address on host is already in use
Examples found in repository?
examples/body.rs (line 17)
5fn main() {
6    let mut app = Express::new();
7    app.post("/", |req, res| {
8        if let Some(body) = &req.body {
9            res.send(body.to_string());
10        } else {
11            res.send("Nobody here...".to_string());
12        }
13    });
14
15    let port = 8080;
16    println!("Starting server on port {}", port);
17    app.listen(port);
18}
More examples
Hide additional examples
examples/get.rs (line 15)
3fn main() {
4    let mut app = Express::new();
5    app.get("/", |_, res| res.send("Hello World!".to_string()));
6    app.get("/hello", |_, res| {
7        res.send("<h1>Hi from /hello!</h1>".to_string())
8    });
9
10    app.get("/redirect", |_, res| {
11        res.status(301)
12            .send("This route has a redirect status code!".to_string())
13    });
14
15    app.listen(8080);
16}

Trait Implementations§

Source§

impl Default for Express

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Express

§

impl !RefUnwindSafe for Express

§

impl !Send for Express

§

impl !Sync for Express

§

impl Unpin for Express

§

impl !UnwindSafe for Express

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> 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, 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.