1. Home
  2. Documentation
  3. Integrating with Dropsource
  4. API Tools
  5. Connect your App to Backendless

Connect your App to Backendless

If you need an API solution to manage your external data from a Dropsource app, Backendless is a quick option that doesn’t require a huge amount of setup that doesn’t require backend development experience. By default the platform allows you to retrieve, update, and create data objects via REST API endpoints without writing any code. The steps below outline using Backendless to setup a simple API and connect to it in your Dropsource app, including user management, retrieving, and adding data.

Create a Backendless App

If you haven’t done so already, log in to / sign up for Backendless and create a new app.

You’ll need your REST API key and the Application ID in order to make requests to the data. Copy them from Manage > App Settings and store them securely on your computer.

backendless keys

Setup your Data

In your Backendless app, open the Data section. Create tables and specify fields for the data items you need, for example a table named “Todo” with a text field named “Task” to store the data for a simple task list app:

backendless add table

backendless schema

You can add some initial sample data if you like to make testing easier:

backendless table

ⓘ Note

If you prefer you can create the tables you need by posting sample data via curl in a terminal. If you’re comfortable with Swagger / OpenAPI, you could define your endpoints in a specification file and send some test requests to post data instead of defining your schema inside Backendless – when your request is processed it will create any tables that don’t already exist.

If you want to restrict access to the data, use the Permissions section for your table. For example, to make the “Todo” items visible only to the user who created them, in Roles Permissions remove access from the Authenticated User section, then grant it in the Owner Policy section.

backendless user permissions

backendless owner

Just adding the data tables is all you need to create the API, as Backendless automatically provides endpoints to access your tables, register, and log users in. When users login, the API will return an access token your app will use to authenticate requests for their data.

Generate API Documentation

In order to use your API in Dropsource, it needs to be documented using a Swagger / OpenAPI specification. Backendless provides an export option – select the REST Console and choose Generate API Docs.

backendless generate spec

Select OpenAPI/Swagger version 2.0 in JSON format and click Generate.

backendless swagger

You can then either copy the specification URL or download the file to import into Dropsource.

backendless export

ⓘ Note

Check out an example spec in the Dropsource GitHub repo.

Backendless spec export is available for the Files API, Publish/Subscribe messaging and Push Notifications API, and Custom API services.

Connect your Data to Dropsource

In your Dropsource project, open the API tab on the right and use the plus plus button to upload your JSON spec file if you downloaded it, or paste the URL to import it from there.

Once imported into your project, you’ll see the available endpoints in the dropdown list.

backendless endpoints

Add the requests to your app pages as required.

Log Users In

To log a user in, add a Device Variable (in Variables on the left of the editor) for the user’s access token, choosing Swift/Java String type.

In the API tab, next to the API name, open the Set Authentication control.

backendless set auth

Select the token variable you created.

backendless token var

Add Device Variables for the App ID and API Key, choosing String type for both.

backendless vars

In the Lifecycle > Application Launched Event, use Set Value Actions to set your APP ID and API Key values from Backendless.

set api key

Add the login endpoint to the page.

backendless login endpoint

Add Text Fields for the email / password, and a Button to submit.

backendless login page

Select the button and in Properties > Events, add an Action to the Tapped Event, adding a Run API Request Action for the login request.

run backendless login

Open the request in the API tab and in Parameters, select Body. Bind the login and password fields to the Text Fields on the page.

backendless login

Select Path from the parameters dropdown list. Bind the API Key and App ID fields by selecting the Device Variables you created.

backendless path

Open the request Events. The 200 Event will fire if login is successful, so add an Action, choosing Set Value. Set the token variable you created with the token value returned from the request (via the Event Data).

set backendless token

You might also want to use a Go To Page Action to navigate to another page when the user has logged in – the app will send the token with any subsequent requests you make to the API.

ⓘ Note

You can use a similar workflow with the register endpoint if you want users to be able to sign up via your app.

Retrieve Data

Once you’ve logged the user in and saved an access token to a variable in your app, you can request the user data. Add a relevant request to a page in your app (e.g. the GET /Todo endpoint in the sample API linked in the spec above, added to the page you navigated to when the user logged in successfully).

Bind the Parameters for API Key and App ID as before.

If the data is returned in an array, use a dynamic Element such as a Table or List to display it – open the Responses and select the Data Source, binding it to the dynamic Element.

select todo table

The request will return a 400 status code if the access token has expired or is invalid, so in Events, add an Action to the 400 Event, choosing Go To Page, navigating to the Login page.

Run the request to retrieve the data, for example in the page Appeared / Resume Event.

run backendless request

Post Data

Add a page to your app that will allow the user to post data to the API. Add any input Elements you need, such as Text Views, Buttons etc. Add the relevant request (for example the POST / Todo endpoint in the sample API). Bind the Parameters for API Key and App ID as before.

Bind any parameters you need for data you’re sending to the API, for example the Body - task field in the sample API.

send backendless

In the request Events, the 200 Event will fire if the data was successfully added, so add any Actions there you need, for example to navigate to a different page.

go to tasks

Run the request, for example on the Tapped Event of a Button.

run post backendless

Test the App!

Use the Test button to try your app out, choosing Test in Web Simulator when it’s ready in the Builds list.

If you continue adding to your Backendless API after importing it into Dropsource, just export your Swagger / OpenAPI specification and update it in your Dropsource project to continue working on your app without losing any of your work.

Was this article helpful to you? Yes No

How can we help?