Route post-requisites
I'm working on a distributed system based on a microservice architecture. I'm extensively using Hapijs for my REST services and I'm moving from an orchestration approach to choreography among services. In this scenario pub/sub events are very important. Basically after a succesful action I want to publish an event to the pub/sub broker. At the same time I absolutely don't want to make my route handlers "dirty" with the event management. onPreResponse extension point seems too centralized for this. For this reason I'm thinking to implement route post-requisites in order to perform actions after the handler execution, decoupling the event managent logic from the handler logic. In your opinion is it feasible to implement such feature? Is it a good direction or I should handle the event management in another way? Thanks
We do this sort of thing during the onPostHandler event, usually ensuring that !request.response.isBoom. You can tie these to particular routes using route-level extension points. You can also write them as policies using mrhorse, though you should know that this plugin doesn't use the route-level server extensions that are now native to hapi.
Ahh, I just realized– this issue actually belongs in hapi/discuss.
You can set onPreResponse per route.