Appcelerator Blog

The Leading Resource for All Things Mobile

Using an Arrow API Mockup to Remove Development Bottlenecks

25 Flares 25 Flares ×

Your mobile app developers are starting a project and need access to an API. However, you’re not ready to develop the API. Perhaps the backend data source is not deployed yet or your API development team is tied up with other projects. You also would like to avoid too much rework, so whatever you create should not be throw-away effort.

This blog post demonstrates how Arrow and ArrowDB can come to the rescue.

The Requested API

The mobile developers are working on a Salesforce mobile app and the screen they are developing displays Salesforce Account data, namely:

name
type
phone

This will enable the end-user of the mobile app to view, filter and sort accounts by name and type and then call the account by pressing on a row in the account list.

ArrowDB API

With Arrow, we can create an API to an ArrowDB schema that matches the needs of the mobile developers.

Use the Arrow Admin Console to create an account model using the ArrowDB connector and create the three fields: name, type, phone as shown in the screen shots below:

Arrow_API_1 Arrow_API_2

This will create the following model, account, in the /models/account.js file in your project folder:


var Arrow = require('arrow');
var Model = Arrow.createModel('account', {
	fields: {
		name: {
			type: String
		},
		type: {
			type: String
		},
		phone: {
			type: String
		}
	},
	connector: 'appc.arrowdb',
	actions: [
		'create',
		'read',
		'update',
		'delete',
		'deleteAll'
	]
});
module.exports = Model;

This will also automatically create all of the CRUD operations and auto-document your account API that your developers requested as shown below:

Arrow_API_3

If you want to limit the exposed APIs, say to remove the Delete APIs, you can edit the account model’s action property.

You can now publish your project using:


appc publish

and provide the published URL to the mobile app developers so they can review the documentation and begin using the API. At this point, you have accomplished your main task since the developers can start building the app using the account API.

For example, I published my project and the account API documentation link is here.

Arrow_API_4

Populate data

One problem that your mobile developers will raise is that the account API has no data.

Currently, there is no import feature to bulk load data into ArrowDB, but that feature is on the roadmap.

In the meantime, of course, they can POST the data manually from the command line using the CURL example provided in the online API docs:


curl -is -X POST -u luvQhStYGGYr4jzWNPTgyvF4S72ZbRIT: "https://3eefc366ee908b5f1c5c62fb174b95acf8e8e866.cloudapp-enterprise.appcelerator.com/api/account" -d '{"name":"ACME","type":"Prospect","phone":"617-555-1212"}' -H "Content-Type: application/json"

A more user-friendly approach for manually loading data is to use the Data tab of the API docs.

Arrow_API_5

Note that you will need the project secret which can be found in the Arrow project /config/default.js file.

You can see one record from my POST above (“ACME”).

Click the New button on the top right of the screen to bring up a form for entering new records.

Arrow_API_6

Now you can more easily populate your data.

Arrow_API_7

Clicking on a row will enable you to delete or modify the record.

Arrow_API_8

Now you or your mobile developers can generate data for the API.

In a separate blog post, I will describe how to upload bulk data to ArrowDB. Stay tuned for this post.

Creating the Production API

At some point, you will be ready to create the production Salesforce account API that is required for the mobile app.

A video describing this process below can viewed here.

Let’s switch back to our local project and install the Salesforce connector using:


appc install connector/appc.salesforce

Configure the connector and create a reduced model based on the Salesforce account model as show below:

Arrow_API_9

Click on the View Fields button and select Name, Type and Phone fields as shown below:

Arrow_API_10 Arrow_API_11

You should notice that the field names of the Salesforce account model are different than those requested by the mobile developer. Namely, the Salesforce field names are capitalized, whereas the fields specified by the developer are not. This will cause an issue as JSON is type sensitive.

Not to worry – we can remedy this easily. Click on each field in the screen above and rename it as follows:

Arrow_API_12 Arrow_API_13

The accountsf model is shown below:


var Arrow = require('arrow');
var Model = Arrow.Model.reduce('appc.salesforce/Account', 'accountsf', {
	fields: {
		name: {
			name: 'Name',
			type: String,
			description: 'Account Name',
			maxlength: 255,
			required: true,
			optional: false
		},
		type: {
			name: 'Type',
			type: String,
			description: 'Account Type',
			maxlength: 40
		},
		phone: {
			name: 'Phone',
			type: String,
			description: 'Account Phone',
			maxlength: 40
		}
	},
	actions: [
		'create',
		'read',
		'update',
		'delete',
		'deleteAll'
	]
});
module.exports = Model;

At this point we can edit the account.js model which is currently published and being used by the mobile application developers. You can edit just a few lines or just replace the contents of account.js with the contents of accountsf.js.

Be careful and notice the line:


var Model = Arrow.Model.reduce('appc.salesforce/Account', 'accountsf', {

This is creating a model called accountsf and you want a model called account, so edit this line as follows:


var Model = Arrow.Model.reduce('appc.salesforce/Account', 'account', {

If you want to, you can delete accountsf.js or just leave it in the project. Then publish your application again after testing it locally.

Once the new version is published, your account API will now be connected to Salesforce and not ArrowDB. You can see this in the Data tab as shown below:

Arrow_API_14

Since the API interface (i.e. field names) have not changed, there is no need for the mobile developers to make any changes. The existing mobile app will now be connected to Salesforce!

25 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 25 Email -- 25 Flares ×

Leave a Reply

Your email address will not be published. Required fields are marked *

Sign up for updates!

Become a mobile leader. Take the first step to scale mobile innovation throughout your enterprise.
Get in touch
computer and tablet showing Appcelerator software
Start free, grow from there.
25 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 25 Email -- 25 Flares ×