January 2019
Intermediate to advanced
520 pages
14h 32m
English
The handler that prints the total quantity of requests also has quite simple implementation, but in this case, we get access to a shared state:
fn counter(req: HttpRequest<State>) -> String { format!("{}", req.state().0.borrow())}
We use the state method of HttpRequest to get a reference to a State instance. Since the counter value is stored in RefCell, we use the borrow method to get the value from a cell. We implemented all handlers, and now we have to add some middleware that will count every request to the microservice.
Read now
Unlock full access