Skip to content

Instantly share code, notes, and snippets.

@sireliah
Created June 28, 2018 22:34
Show Gist options
  • Select an option

  • Save sireliah/275c3e36a79c3b6a4f61601fc2659fe2 to your computer and use it in GitHub Desktop.

Select an option

Save sireliah/275c3e36a79c3b6a4f61601fc2659fe2 to your computer and use it in GitHub Desktop.
extern crate hyper;
extern crate futures;
use hyper::{Body, Method, Request, Response, StatusCode};
use hyper::server::Service;
use futures::future::Future;
struct SomeAPIService;
impl Service for SomeAPIService {
type Request = Request;
type Response = Response;
type Error = hyper::Error;
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
fn call(&self, req: Request<Body>) -> Self::Future {
println!("{:?}", req);
match (req.method(), req.uri().path()) {
(&Method::Post, "/internal/create") => {
let request_body = req.body();
println!("{:?}", request_body);
Box::new(futures::future::ok(Response::new()))
},
_ => Box::new(futures::future::ok(
Response::new().with_status(StatusCode::NotFound)
)),
}
}
}
fn main() {
let address = "127.0.0.1:6000".parse().unwrap();
let server = hyper::server::Http::new()
.bind(&address, || Ok(SomeAPIService {})).unwrap();
server.run().unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment