Look Ma, No Servers!
My team and I at Parse have worked hard to create a platform that lets developers avoid having to think about or code anything on the server-side. You’ll notice that the codebase is just a static HTML5 app. You can easily throw this behind Nginx or even host it directly on AWS. Before embarking on this tutorial, you can sign up for a free account on Parse and have your app keys ready.
From Backbone to Parse
Parse.Collection classes are compatible with Backbone Models and Collections. This tutorial is a step-by-step guide on how to convert CloudEdit to use Parse. There are also general conversion instructions on the Parse documentation page.
Let’s get started!
The structure for the HTML5 is extremely simple since the whole site is static. We’ve reduced down to two main directories, with a similar hierarchy in the
index.html stylesheets/ js/ application.js controllers/ documents.js models/ document.js views/ show.js index.js notice.js
Converting the Document Model
CloudEdit lets users create simple documents that have a title and body, and that are immediately publicly editable. To convert the document Backbone model to Parse, we simply replace the classes appropriately and specify a Parse
And that’s it. Notice that we can get rid of the notion of urls entirely and reduce the model to be backed by a named class on Parse.
Converting the Collection
Converting the collection is just as easy:
Again, we simply get rid of the
url attribute and point the collection over to the new Parse Object class. Everything just works the same.
But, it turns out we can get rid of the collection class altogether. Since it’s such a simple collection, we can automatically create an instance of this collection from a
Parse.Query. Here’s how we do it:
We create a query to get all documents and limit it to 50 documents. We then generate the proper collection using the
Views and Controllers
We don’t have to do anything major to convert the Backbone views and controllers, since they don’t involve the data models.
As for the templates, I converted from the original JST templates over to underscore templates directly in index.html. Also, I combined various Rails templates to make index.html. You could also simply copy and paste the rendered output directly to create the index page.
There’s one last thing we need to do, and that is to initialize the Parse SDK with your application keys:
We also create a user automatically for each client by generating a username and password. This is crucial for security. You can read more about security and ACLs in the guide.
And, that’s it. You can check out the fully functioning app here.
Backbone Apps Without Servers
With Parse, we’re hoping to usher in an age of apps without servers. Or, at least, without servers that you as the developer have to worry about. What’s great is that by following this guide, you’ll be able to convert your existing Backbone apps to Parse with ease.
And, this is just the beginning. Read the full documentation to learn about user authentication, security, queries, geopoints, and much more.