Blog

How to Create Server-Side Cloud Code for User Service API with Console

by on May 3, 2015

In another 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 an event handler, minus the actual business logic (Cloud Code) 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:

  1. In the Backendless Console, click the Business Logic icon.
  2. 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).
  3. Click the Add Event Handler button.
  4. 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.

When you click Save, Backendless Console automatically generates the code for the event handler:

Similarly to Timers, you can download the code to add your own business logic.

Enjoy!