Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Last active July 4, 2017 00:20
Embed
What would you like to do?
> loc src
--------------------------------------------------------------------------------
Language Files Lines Blank Comment Code
--------------------------------------------------------------------------------
Rust 1 89 24 0 65
--------------------------------------------------------------------------------
Total 1 89 24 0 65
--------------------------------------------------------------------------------
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