Message:

Quick Start Guide for integrating Backendless with Backbone.js

This guide will help you get up and running with Backendless quickly so you can develop Backbone.JS applications on top of our services. At the end of the guide you will have a configured working environment and a basic project with the code communicating with the Backendless services.

  1. Login to your Backendless account or register to create a new one.
  2. Install node and npm
  3. Create a new directory which will contain your application project.
  4.  Create  package.json file with the following contents in the root of your application directory:
  5. Create index.html  file:
  6. Create  app.js file which will contain your JavaScript code. The file will be empty for now – you will add code as you progress through the guide.
  7. At this point your environment is configured. To finalize it, run the following command to download all the libraries required by the project (the libraries and their dependencies are defined in package.json  created in step 4):
  8. Get your Backendless application keys for Backendless SDK for JavaScript from the Backendless Console. The keys can be found in the Manage > App Settings section:js keys - Quick Start Guide for integrating Backendless with Backbone.js
  9. Add the Backendless application initialization code shown below into app.js. Copy/paste the application ID and JavaScript secret key into the code:

At this point the application has the bare minimum required code to work with Backendless. The steps below will demonstrate how to use various Backendless APIs:

User Registration

  1. Add the following code to app.js. The code should be added after the Backendless.initApp  line. The code registers a user in your app’s backend. Instead of michael@backendless.com used in the code below, consider using an email address  where you can check email – your Backendless backend will send out an email welcoming the user to your app.
  2. Open index.html  in a browser – you can open it by double-clicking the file in the file system. Once the browser opens the file, it runs the code which registers the user. You will not see anything in the browser, since there is no code to update the user interface (unless you open the Network tab for the browser’s developer tools, which will show the network traffic).
  3. You can verify the registered user in the Data section of the Backendless Console:
    new user created - Quick Start Guide for integrating Backendless with Backbone.js

Data Persintence

  1. In order to experience the Backendless Data Service API a Backbone model must be created. Instances of the model class can be saved using the Backendless API. The class is going to be called Comment, it will also correspond to a table with the same name. The code below must be added in app.js  right after user registration logic:
  2. The code below creates a new instance of the Comment  class. It then uses the Backbone.JS save method to store the object in Backendless. Add the following code into app.js , it should be added right after the line where Backbone model is extended.
  3. Save the file and reload index.html  in the browser which will run the code you just added.
  4. Now you can verify in the Backendless Console that the Comment data table has been created with the columns corresponding to the properties of the Comment class and it contains the saved instance.
    comment record - Quick Start Guide for integrating Backendless with Backbone.js

Finally all your code should look like this:

package.json:

 

index.html:

app.js:

Enjoy!