kurierjs / kurier

TypeScript framework to create JSON:API compliant APIs
https://kurier.readthedocs.io/en/latest/
MIT License
61 stars 9 forks source link

Implement hooks for addons #340

Closed joelalejandro closed 1 year ago

joelalejandro commented 1 year ago

Hooks are a basic way for addons to extend behavior in the request-response pipeline, at the middleware layer.

The following hooks are supported:

A hook can be registered from the app object, which receives two parameters: the appInstance and a hash containing a variety of properties. For example:

app.hook('beforeAuthentication', async (appInstance: ApplicationInstanceInterface, parameters: Record<string, any>) => {
  // Do your magic here.
});

app.hook('beforeRequestHandling', async (appInstance: ApplicationInstanceInterface, parameters: Record<string, any>) => {
  // Do your magic here.
});

At the moment, parameters is comprised of:

You can register as many hook functions as you need by calling app.hook for each hook function you define.