Subscribe rss
Blog categories
All | Backendless features
Feature 119: Custom server-side code to handle Data Service API events
May 8, 2015 by markpiller

The custom business logic feature in Backendless lets you add your own server-side code to handle client API requests. In this post I am going to review how to add the Data Service API handlers.

With that type of handler you can intercept and add additional logic for the APIs which store data in Backendless, run queries, update or delete data objects.

The easiest way to start building server-side Backendless code is the developer console. Login to your account, select an app and click the Business Logic icon. I assume there are some data tables in your backend, if not, make sure to create a few. Since we are going to add an event handler which works with persistent data, click Data Tables from the list of available handler categories. Click Add Event Handler, the screen should look as shown below:

Items in the Event drop-down list correspond to the APIs available in Data Service:

The Context list shows a list of available data tables. A selection in that list determines for which table the event handler will be processing the API events. Notice there is a special value of *(All Context). When selecting that option the event handler will process API events for all data tables:

I added an event handler for the Order table and selected the Create event. Backendless generated the minimally necessary code for the event handler:

Take a closer look at the generated code:

Specifically, notice that one of the arguments for the beforeCreate method is the Order class. This is a very powerful feature. Indeed, the client side of the API may be a REST client, or an iOS or a JavaScript app. Yes, the data describing an order is morphed into an instance of the Java Order class by Backendless and provided to your custom code. The source code for the Order class is also created by Backendless (see the screenshot above). This is what the Order class looks like:

The class can be used to check or modify the values received from the client app.

The rest of the process for working with the custom event handler is the same as had been described before. You can download it for local debugging and then deploy to the Backendless servers.


Share this post
Tweet about this on TwitterShare on FacebookGoogle+