pub struct Express { /* private fields */ }
Implementations§
Source§impl Express
Main application object
impl Express
Main application object
Provides ways to mount path and method combinations and assign functions to them.
Sourcepub fn new() -> Self
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
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}
Sourcepub fn get<F>(&mut self, path: &str, callback: F) -> &mut Self
pub fn get<F>(&mut self, path: &str, callback: F) -> &mut Self
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}
Sourcepub fn post<F>(&mut self, path: &str, callback: F) -> &mut Self
pub fn post<F>(&mut self, path: &str, callback: F) -> &mut Self
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}
pub fn put<F>(&mut self, path: &str, callback: F) -> &mut Self
pub fn delete<F>(&mut self, path: &str, callback: F) -> &mut Self
pub fn patch<F>(&mut self, path: &str, callback: F) -> &mut Self
Sourcepub fn listen(&mut self, port: u16)
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
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§
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> 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