The term "hooks" is used to describe a technique used to alter the flow of an application, extend its functionality, or intercept specific events. This function allows third-party program sequences to be integrated into existing applications at specific points without modifying the original code base.
Hooks can be integrated directly into the modified source code. Alternatively, they can be integrated via configuration files, which changes the flow of a finished program. However, they can also be triggered by calling functions from the program code to be executed.
Hooks may be executed in an asynchronous or synchronous manner.
Asynchronous (fire and forget)
Once a hook has been initiated, the application continues to run without waiting for feedback from the executed hook. This format is primarily utilized for the dissemination of notifications. To illustrate, consider the following example: Once a user has successfully registered in an application, an asynchronous step sends a message to the administrator, notifying them of the registration. The application itself continues to run in the interim.
Synchronous
In the basic synchronous step, the application pauses until the hook has been processed by the program. However, a potential return value is not processed.
Synchronous with consideration of the return value
In addition, there is the synchronous step, where the return value is taken into account. A potential use case would be to verify whether an email address used for registration is permitted with an external service.
The aforementioned steps can be compared to the process of a paperboy delivering newspapers. In the asynchronous step, he proceeds along the street with determination, distributing the daily newspapers in front of each door. In the basic synchronous step, he dismounts, presents the newspaper to each recipient, and awaits acceptance. It is irrelevant whether the newspaper delivered was the correct one. The synchronous step with a return value is analogous to the simple synchronous step. The distinction is that, in the event of an incorrect newspaper being delivered, a subsequent action is initiated. For instance, the transfer of the correct newspaper.
At Engity, we use the asynchronous step and the synchronous step with return value for the following three types of hooks:
Webhooks
Webhooks are automated messages triggered by an event that are sent from one web application to another. Technically speaking, this is an HTTP callback or HTTP POST request. In other words, an HTTP POST message is sent to a prepared URL in order to receive the requested data.
Server-side Hooks
These are code snippets that are based on the LUA scripting language and are stored on Engity's servers. Synchronous steps can be executed more quickly with server-side hooks, as there is no need for communication across servers.
Generic Hooks
In essence, these are predefined templates that are partially customizable and function like server-side hooks. In other words, they are not code snippets that are stored on the Engity server by the customer, as is the case with server-side hooks.