This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > loc src | |
| -------------------------------------------------------------------------------- | |
| Language Files Lines Blank Comment Code | |
| -------------------------------------------------------------------------------- | |
| Rust 1 89 24 0 65 | |
| -------------------------------------------------------------------------------- | |
| Total 1 89 24 0 65 | |
| -------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main() { | |
| let host = "127.0.0.1"; | |
| let port = "7878"; | |
| fn handler(request: Request<&[u8]>, response: &mut Response<&[u8]>) { | |
| println!("Request received. {} {}", request.method(), request.uri()); | |
| match (request.method(), request.uri().path()) { | |
| (&method::GET, "/hello") => { | |
| *response.body_mut() = "<h1>Hi!</h1><p>Hello Rust!</p>".as_bytes(); | |
| } | |
| (_, _) => { | |
| *response.status_mut() = status::OK; | |
| *response.body_mut() = "<h1>404</h1><p>Not found!<p>".as_bytes(); | |
| } | |
| } | |
| }; | |
| let server = Server::new(handler); | |
| server.listen(host, port) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment