Skip to content

Instantly share code, notes, and snippets.

@brianloveswords
Last active September 29, 2015 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianloveswords/33cae0ff7b2246b3475c to your computer and use it in GitHub Desktop.
Save brianloveswords/33cae0ff7b2246b3475c to your computer and use it in GitHub Desktop.
extern crate hyper;
extern crate uuid;
use uuid::Uuid;
use hyper::server::{Request, Response};
use std::io::Read;
// If a github webhook client requests this route, after serving that request successfully
// it will never respond to another request from any client again.
fn hello(req: Request, res: Response) {
let mut req = req;
let task_id = Uuid::new_v4();
println!("[{}]: request received, processing", task_id);
println!("[{}]: loading body into string", task_id);
let mut payload = String::new();
if req.read_to_string(&mut payload).is_err() {
println!("[{}]: could not read body into string", task_id);
return res.send(b"nope").unwrap();
}
println!("[{}]: done, responding", task_id);
res.send(b"yep").unwrap();
}
fn main() {
let _listening = hyper::Server::http("0.0.0.0:4200").unwrap()
.handle(hello);
println!("Listening on 0.0.0.0:4200");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment