Skip to content

Quick Start Guide

This guide will walk you through creating a reusable function which calculates a Fibonacci number for its sequential position. You will learn how to declare a function, add an input parameter, add Codeless logic and re-use the function.

  1. Login to your Backendless application and click the Business Logic icon.
  2. Click the CODELESS tab and click Add New under Functions in the BROWSER panel.
  3. When visiting the Function Library section for the first time, a new function placeholder is automatically created for you. In the function block, click the doSomething label, change it to fibonacci:
  4. The function will have one input, which identifies the position of the Fibonacci number to calculate. To add the input, click the gear icon in the upper left corner of the Function block. Drag the input name block into inputs, then change the name of the input from x to position as shown in the video below. Notice the declared input is automatically added to the Context Blocks area:

  5. The function developed in this guide will return a value (the actual Fibonacci number), however, when you develop other functions which do not need to return a value, you can control it through the interface behind the "gear" icon:
  6. The algorithm which will be implemented in the function assumes that the first two numbers in the sequence are 1 and 1. All other numbers are the sum of the previous two. Thus the logic of the algorithm is going to be:

    If the position argument is less than or equals 1, then the function should return 1. Otherwise, the function should recursively get the result for position - 1 and add it to the result for position - 2.
  7. Since the logic of the function will use recursion (the function will call itself), make sure to click SAVE so that the function shows up in the Custom Functions category:
  8. The final logic should look as shown below. Notice the function is re-used recursively:
    The video below demonstrates the process of composing the logic for the function:

  9. When finished composing the logic, click the SAVE button. At this point the function implementation is complete. To see the function in action, you will create an API Service which uses the function. Click CLOSE and switch to the API Services screen.
  10. Click the "+" icon to create a new service and select the CODELESS tab. Enter MathService for the Service Name field and click SAVE.
  11. In the New Codeless Method popup enter calculateFib for the method name and N for the parameter 1 field. The type of the parameter must be Number. Click SAVE:
  12. Click EDIT to edit the codeless logic for the calculateFib method:
  13. In the Business Logic Designer drag the fibonacci block from the Custom Functions category and attach it to the return connector of the calculateFib method. Drag the Method Argument N block from Context Blocks and attach it to the position connector of the fibonacci block. Click DEPLOY to deploy the logic.

  14. At this point the service method is ready. It uses the custom function and can be tested with real data. Click the CLOSE button in the Business Logic Designer. Click the PARAMETERS tab. Enter a value for the argument N and click INVOKE. Backendless Console invokes the service and displays the result. For example, the screenshot below shows that the Fibonacci number for the 10th position in the sequence is 89:
  15. This concludes the guide. You have developed a custom reusable function and built an API service which uses the function.