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.

Document the API

In order to use your API in Dropsource, you need to document it using a Swagger / OpenAPI specification. The Dropsource team recommends using Stoplight to author your spec – feel free to use this sample version for the task list API mentioned above to get your own started.

Add each endpoint to your specification, specifying the parameters, auth, request and response structures.

stoplight backendless

If you’re adding your own endpoints, a quick approach is to run them via curl and paste the request/response markup into Stoplight as an example to generate your schema from:

backendless stoplight eg

The detail will depend on your data and the operations you plan to perform on it from the Dropsource app, but in general:

  • Indicate application/json for the Consumes and Produces properties on each endpoint. consumes produces
  • Include path parameters for the API Key and App ID in each endpoint using the format /{app-id}/{api-key}/data/endpoint-name.
  • Specify API Key Auth in the Security Schemes for your API and in endpoints that query or update user data. stoplight api key Include a Request Header on these endpoints, named user-token, with String type. stoplight user token
  • Include a Request Body on all POST endpoints.
    • For user login the body should have the format:

      login request body
    • For endpoints creating or updating data, the format will need to match your data structure, like this example for the task list API:

      task schema
  • Include a Response Body in all endpoints.
    • For login the 200 response should have the form:

      post login response
      Login will return a 401 status code if the operation fails – to respond to this in your Dropsource app, add the status code to your spec also. login 401
      You can add a registration endpoint if you want users to be able to sign up via your app – the detail is very similar to the login endpoint (see the sample spec).
    • For default GET endpoints returning the data from a whole table, the 200 response will be structured as an array:

      get array schema
      Requests to query or update user data will return a 400 status code if auth is unsuccessful. response 400
    • Endpoints creating or updating data will return a 200 response like this example for the task list API:

      post data response schema

There are lots of optional fields you can include in your requests, for example the task list spec includes a sortBy query parameter in the GET endpoint to retrieve tasks – see the Backendless docs for more detail on what the options are.

It’s worth trying to send some test requests inside Stoplight to make sure your spec does what you need it to. When you’re happy with it, export your specification from Stoplight as an OAS (Swagger 2) JSON file and save it to your computer.

ⓘ Note

The sample spec specifies the API Key and App ID as path parameters, but you could alternatively hard-code your values along with the rest of the API URL in the host field.

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.

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 My Builds list.

If you continue adding to your Backendless API after importing it into Dropsource, just add any changes to 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?