January 2019
Intermediate to advanced
520 pages
14h 32m
English
We have to reorganize the code of microservice_handler because we can't use regular expressions in a match expression. We have to extract the method with the path at the start, because we need it for most responses:
let response = { let method = req.method(); let path = req.uri().path(); let mut users = user_db.lock().unwrap(); // Put regular expressions here};futures::ok()
The first thing we'll check is the index page requests. Add the following code:
if INDEX_PATH.is_match(path) { if method == &Method::GET { Response::new(INDEX.into()) } else { response_with_code(StatusCode::METHOD_NOT_ALLOWED) }
This uses the INDEX_PATH regular expression to check whether the request's path matches the index page request using the ...
Read now
Unlock full access