A backhook is basically a function that knows from where it has been called. It means that it holds some state bound to a specific context.
This has many advantages:
- Better typing: Today, most of the context bindings are made by attaching new properties to a request object. That makes typing complicated and not reliable. When using backhooks, your typing is always accurate.
- Easier APIs: If you're a library developer, and want to provide a function that relies on headers for a function, you can write it without taking the headers as parameters and instead use other hooks to retrieve it. It simplifies everyone's life.
- They are many ways to use backhooks, from retrieving the authenticated user in the current context to aggregate logs with a requestId to make it easy to trace them.
I'll be happy to response to any other questions! Thanks for taking the time to comment.