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.
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:
You can add some initial sample data if you like to make testing easier:
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.
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.
Select OpenAPI/Swagger version 2.0 in JSON format and click Generate.
You can then either copy the specification URL or download the file to import into Dropsource.
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
Once imported into your project, you’ll see the available endpoints in the dropdown list.
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.
Select the token variable you created.
Add Device Variables for the App ID and API Key, choosing String type for both.
In the Lifecycle > Application Launched Event, use Set Value Actions to set your APP ID and API Key values from Backendless.
Add the login endpoint to the page.
Add Text Fields for the email / password, and a Button to submit.
Select the button and in Properties > Events, add an Action to the Tapped Event, adding a Run API Request Action for the login request.
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.
Select Path from the parameters dropdown list. Bind the API Key and App ID fields by selecting the Device Variables you created.
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).
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.
You can use a similar workflow with the register endpoint if you want users to be able to sign up via your app.
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.
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.
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.
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.
Run the request, for example on the Tapped Event of a Button.
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.