January 2019
Intermediate to advanced
520 pages
14h 32m
English
Our service function will support two kinds of requests:
To detect the corresponding method and path, we can use the methods of the Request object. See the following code:
fn microservice_handler(req: Request<Body>) -> impl Future<Item=Response<Body>, Error=Error>{ match (req.method(), req.uri().path()) { (&Method::GET, "/") => { future::ok(Response::new(INDEX.into())) }, _ => { let response = Response::builder() .status(StatusCode::NOT_FOUND) .body(Body::empty()) .unwrap(); future::ok(response) }, }}
Read now
Unlock full access