Quick overview of benefits to building a CouchApp:
- built-in data replication capabilities
- runs everywhere (desktops, servers and mobile devices)
- empowers new types of open source business models
Each one could probably be it’s own section but I’ll save deeper dives for later.
If your new to CouchDB here are some quick highlights to get you excited:
- data stored in schema-free documents as JSON objects
- files can be stored as attachments and served directly from the database
- powerful replication capabilities with built-in version control
- it speaks HTTP and features a rich RESTful API
With the highlights covered let’s dig a little deeper to see what makes a CouchApp a CouchApp.
That was one my first questions when I first started wrapping my head around CouchApp concepts. The short answer is they’re all served up as attachments using the built-in HTTP server (more on that in a sec).
To create a CouchApp you start by creating a design document which is a special document that can contain CouchDB application code. This is where you put all your CouchDB views, lists and show functions among other goodies.
Once your app is loaded into Couch you can hit the url for your index.html file and it gets served up along with all its referenced files just like a traditional web server.
Manually pushing all your files into CouchDB as attachments and updating them anytime you want to make a change would be a pretty tedious process. Fortunately there few tools out there that fully automate the process.
I’ve been using nodecouchapp. It’s an easy to use NodeJS module that helps setup a CouchApp project, push files into CouchDB and update files when they change. Other folks are using a python based tool aptly name couchapp.
Check out both tools and decide which works better for you, just keep in mind they’re not interchangeable so you’ll want to pick one and stick with it.
Just about anything you need to do with CouchDB can be done using the HTTP API. This includes storing and retrieving all your data as well as managing replication settings, resolving replication conflicts and more. If your new to Couch check out the getting started chapter of O’Reilly’s online book CouchDB the Definitive Guidefor a quick walkthrough.
With a little tweaking the new RestProxy in Ext JS 4 maps pretty well to the basic CRUD operations of the CouchDB HTTP API.
For Hub List I extended the RestProxy to turn flat JSON responses from CouchDB into an ordered hierarchy of models that I use with TreePanels. As it evolves I’d like turn it into a more generalized CouchDB Proxy to share with the community.
The easiest path is take advantage of the JsonPProxy in Ext JS. The JsonPProxy works pretty easily but limits you to GET requests. For more flexibility you can use the standard AjaxProxy with some extra steps to support CORS. With a bit more integration effort you can leverage websockets/socket.io for real-time communication!
Whatever path you choose clears the way to making external calls to your own server side applications or third party APIs. I’m especially excited about using theSocket.io client library and looking forward to integrating it alongside Ext JS Server Proxies.
iCloud brings some much needed attention to the developer pain-point of data synchronization and Apple’s positioning opens a new opportunity to address the problem outside their ecosystem. CouchDB has the cross platform compatibility, data replication features and the open source pedigree to become that solution.
It’s not all sunshine and rolling hills in the world of CouchApps. The movement is still pretty new and there are lots of things to be worked out and refined.
Being a noob to CouchDB there was a bit of a learning curve to get everything working smoothly for the new version of Hub List. I still haven’t found solid docs on packaging a CouchApp as a native application for desktops but there’s an interesting PhoneGap project on the mobile front and I hope to see more spring up!
After learning some of the benefits and tradeoffs of CouchApps I hope you’re excited to try them out! I’d like to make this the first in a series of posts to help other Ext JS devs start building CouchApps, stay tuned!