Skip to content

Framework Hooks

Danny edited this page Jun 2, 2021 · 1 revision

Framework Hooks

Framework hooks are a new feature that offer functionality for hooking functions into the framework's internal events, at the moment they are fairly basic, but as they are added to, I shall update this information here.


Available Hooks

The below table defines the available hooks, in-depth information for each hook is lower down.

Hook Description Parameters
init This hook will run while the framework is initialising with the different state. state: string
register This hook is called when a module is registered, this could be a controller, model, service, etc. moduleDefinition: object
start This hook, similar to the init hook, is called before and after starting the framework. state: string
http This hook is called every time a HTTP request is received, and the context is generated and passed with the hook. context: IContext
ws This hook is called every time a WebSocket request is received, and the context is generated and passed with the hook. context: IContext
service This hook is called every time a service will run, the service definition is passed over. serviceDefinition: object

Hook In-Depth

Hook: init
The init hook is called while initialising the framework, you can use this to check whether things are running as expected, the only parameter that is passed over is the state, which is either pre_init or post_init.

Hook: start
This hook is called while starting the framework, very similar to init except that the available states are: pre_start and post_start.

Hook: register
This hook is called when a module is registered, this could be a database driver, guard, service, provider, controller, or model, you will get the definition of the hook as well, due to pass by reference it means you can hook extra data into the module before starting the framework.

Hook: service
The service hook is called when a service is about to run, you will receive the actual service definition as a parameter as well.

Hook: http
The HTTP hook is called every time a HTTP request is received, you will then get the generated context passed over, so you can actually use a hook to reject specific requests, or extend functionality.

Hook: ws
Similar to the HTTP hook, but instead of WebSocket requests, this will only be called when a WebSocket connection actually makes a request, but I plan to extend this or change it to support, on connect, on disconnect, on error and on message, and offer a raw data opportunity instead.

Useful Links:

Clone this wiki locally