January 2019
Intermediate to advanced
520 pages
14h 32m
English
The handler function of the image-resizing microservice contains two branches: one for the index page and one for the resize request. Take a look at the following code:
fn microservice_handler(tx: mpsc::Sender<WorkerRequest>, req: Request<Body>) -> Box<Future<Item=Response<Body>, Error=Error> + Send>{ match (req.method(), req.uri().path().to_owned().as_ref()) { (&Method::GET, "/") => { Box::new(future::ok(Response::new(INDEX.into()))) }, (&Method::POST, "/resize") => { let (width, height) = { // Extracting parameters here }; let body = ; // It's a Future for generating a body of the Response Box::new(body) }, _ => { response_with_code(StatusCode::NOT_FOUND) }, }}
In the resize branch part of ...
Read now
Unlock full access