Deploying LoopBack mBaaS On Rackspace

Filed in Mobile by Matt Schmulen | September 30, 2013 2:00 pm

This is a guest post written and contributed by Matt Schmulen, Developer Advocate at StrongLoop Inc.[1], whose suite offers an API tier for connecting enterprise data to devices and browsers. StrongLoop was created by the people who write Node.js. StrongLoop’s LoopBack[2] is an open source mobile backend-as-a-service (mBaaS) that is available on Rackspace.

Fanatical Support Meets Strong Node

Fanatical Support has made Rackspace a leader[3] in enterprise hosting. The Fanatical[4] Support mantra, support for open source products and strong SLA has made it the preferred vendor for IT ops in companies large and small. StrongLoop is excited to be one of the first available Node providers for Rackspace’s new Deployments service[5], which allows you to create and configure your multi-machine Node topology in minutes.  StrongLoop Suite integration in the Cloud Control Panel means you’re three clicks from Strong Node, Strong-Ops and LoopBack.

Push Button, Receive Server

The easiest way for you to start using Node is via the Rackspace Cloud Control Panel. Log into your console at https://mycloud.rackspace.com[6] and select “Deployments” view on the right of the control panel.  The Rackspace Deployment Service[7] is a new offering that makes it easy to automate the launching of your app in the Rackspace Cloud. It works great with the StrongLoop Suite by automating an application and resource deployment in a best practice configuration.

To Startup a Rackspace hosted StrongLoop Application, login into your mycloud.rackspace.com control panel and select  ‘Deployments’ on the right side of the Servers bar.

From the Rackspace “Create Deployment” panel, insert your deployment’s name and select your region. Click the “StrongLoop LoopBack” Blueprint.

Then configure your StrongLoop server deployment options: Site Address, Admin settings and application name.

Select your Deployment machine options.

Click the “Create Deployment” button to provision your server.

Fortunately, the StrongLoop install pack is very lightweight so your newly configured StrongLoop Node server will be ready in a few minutes.  When you see the Server Status “go Green” you know your server is up and waiting for you.

Start Server, Receive Open Node MBaaS

Now that you’re newly created StrongLoop server is up.  Let’s take a look at what you get.

The StrongLoop Suite has three main components:  StrongNode, StrongOps and – most important for this posting – LoopBack.  LoopBack is an open source Mobile API tier.  The rest of this post will show you how to configure your loopback server and connect it to a Native iOS mobile application.

First, take note of the public IP address that is presented to you once your server is activated.

We will use this IP address to configure the native mobile adapter allowing the iOS LoopBack SDK to connect to your mobile backend.  Let’s download the iOS example apps from the https://github.com/strongloop-community/loopback-examples-ios[8] Github repo.  The LoopBack examples Repo has sample code to show you how to connect your mobile application to the LoopBack server using the native LoopBack SDK.  You can find additional documentation about LoopBack and the iOS SDK at the StrongLoop docs site docs.strongloop.com[9].  This article will show you how to connect to the UITableView example, however configuring the MapView and custom remote method sample can easily be configured.

Once you have the repository cloned to your iOS development machine.

$git clone git@github.com:strongloop-community/loopback-examples-ios.git

Open the tableview-example.xcodeproj located at ‘loopback-examples-ios/ios-tableview-simple-example/tableview-example.xcodeproj’

The loopback-examples-ios applications has a LoopBack mobile server bundled with the repo ‘/loopback-examples-ios/loopback-nodejs-server’ that can be run on the developer’s host machine by calling ‘slc run app.js’ from within the server folder.  However, for this demo we will leverage our newly-provisioned LoopBack instance on the Rackspace Cloud infrastructure.

Verify the Loopback server is running on the Rackspace installation and the ‘products’ endpoint is available.  Open a web browser and point it to the LoopBack API explorer that come pre-configured with your LoopBack instance http://HOST-IP-ADDRESS:3000/explorer/[10].

Now that you have your StrongLoop Suite (Strong-Node, Strong-Ops and LoopBack) up and configured in your Rackspace environment, you can simply configure the native iOS application to point to the mobile API.

From within XCode project, open the AppDelegate.m file and configure the adapter URL to “http://RACKSPACE_IP_ADDRESS”.

Run the Application in the XCode iOS simulator by pressing the ‘Run’ button in the top left or using the hotkey combination (?+R). From the simulator click the ‘Inject Data’ button in the top left to insert three ‘product’ model instances into the LoopBack server.  Naturally, you will see the records appear on the mobile device, but you can also verify the server content by opening the API Explorer http://localhost:3000/explorer/#!/products/products_find_get_4 [11] to the Get Request and pressing the ‘Try it out’ button.

Additionally, you can add data to the backend from the API Explorer as well from the ‘POST’ button by inserting the model JSON data { “name”: “Matts Product”, “inventory” : 22 }  in the ‘Value’ field. Pressing refresh on the mobile client will sync the tableView.

Notice the model definition is dynamic, allowing the mobile developer to dynamically add parameters to the ‘product’ mobile model type; this allows the mobile developer to quickly extend and configure the Mobile Object to fit the applications need.  LoopBack also supports static schema configuration for situations where the model data may be directly bound to a traditional static data stores such as Oracle or MySQL.

Take some time and explore the mobile application as well as the LoopBack Node server. You can find more detailed information on how LoopBack handles both static and dynamic model types at http://docs.strongloop.com/loopback/#sanitizing-and-validating-models. Then give the integration a run on Rackspace[12].

Endnotes:
  1. StrongLoop Inc.: http://strongloop.com/
  2. LoopBack: http://strongloop.com/strongloop-suite/loopback/
  3. leader: http://www.rackspace.com/information/aboutus/gartner/
  4. Fanatical: http://www.rackspace.com/whyrackspace/support/
  5. Deployments service: http://www.rackspace.com/blog/cloud-applications-automated-for-you-rackspace-deployment-now-available-to-all-customers/
  6. https://mycloud.rackspace.com: https://mycloud.rackspace.com/a/rsstrongloop/#deployments
  7. Rackspace Deployment Service: http://www.rackspace.com/blog/automate-your-deployments-quickly-easily-launch-your-app-in-the-rackspace-cloud/
  8. https://github.com/strongloop-community/loopback-examples-ios: https://github.com/strongloop-community/loopback-examples-ios
  9. docs.strongloop.com: http://docs.strongloop.com
  10. http://HOST-IP-ADDRESS:3000/explorer/: http://localhost:3000/explorer/
  11. http://localhost:3000/explorer/#!/products/products_find_get_4 : http://localhost:3000/explorer/#%21/products/products_find_get_4
  12. Rackspace: http://Rackspace.com

Source URL: http://www.rackspace.com/blog/deploying-loopback-mbaas-on-rackspace/