pub struct Response {
pub stream: String,
pub headers: Vec<String>,
/* private fields */
}
Expand description
Represents a HTTP response
Fields§
§stream: String
§headers: Vec<String>
Implementations§
Source§impl Response
impl Response
pub fn new() -> Self
Sourcepub fn send(&mut self, s: String)
pub fn send(&mut self, s: String)
Writes plain text to the response buffer
Examples found in repository?
examples/body.rs (line 9)
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 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 status(&mut self, status: u16) -> &mut Self
pub fn status(&mut self, status: u16) -> &mut Self
Change the status code of a response
§Examples
use express_rs::Express;
let mut app = Express::new();
app.get("/", |_, res| {
res.status(301).send("This route has a custom status code".to_string())
});
Examples found in repository?
examples/get.rs (line 11)
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§
impl StructuralPartialEq for Response
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
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