In my previous post I introduced the feature of server-side API event handlers – a mechanism for injecting custom business logic into Backendless. In this post I am going to review the process of creating an event handler for User Service APIs using Backendless console. The User Service APIs include: user registration, login, logout, user update, password recovery and retrieval of user schema (a list of user properties and their types). You can build an event handler (or two event handlers – “before” and “after”) for each of these operations.
To simplify the process of developing event handlers, we developed a code generator which is included into Backendless Console. The code generator can create all the required code for event handler, minus the actual business logic which is all that’s left for you to add. For example, suppose a business logic must be triggered every time a user registers with your app . To create an event handler for that API:
- In the Backendless Console, click the Business Logic icon.
- Select Users in the list of Event Handlers (the reason you need to select “Users” is because we are adding an event handler for one of the User Service APIs).
- Click the Add Event Handler button.
- Select Register from the Event drop-down. Your screen should look as shown below:
As you can see, the user interface lets you pick an event for which you’re going to create an event handler. You can also select the “timing” of the handler by selecting the “Before” or “After” option. Finally, you can choose the event handler to be executed either synchronously or asynchronously. The latter means the API processing chain will not wait for the handler to complete its execution.
Similarly to Timers, you can download the code to add your own business logic. In the future posts I will be reviewing the process of debugging and deploying the event handlers to Backendless.