We're on a Mission to Make it Easy

By Brad Noble

Cloudant isn't like other databases. So it goes that the content we present to developers in our newly minted For Developers section isn't like other tech documentation; i.e. it's not static. More on that in a minute.

First, a bit about the world we live in...

Cloudant is a hosted, distributed database service. Apps write to and read from Cloudant using our RESTful API. The payload is lightweight JSON. For all of that, you may be thinking it'd take a lot time to get Cloudant set up in order to play with it, and kick the tires. Nope. All it takes is the five or so seconds to fill out the sign up form.

And so...

So long, static

More than just docs, the For Developers section is a live demo of the data layer at work. Click a couple buttons to CRUD, get JSON via secondary indexes and search the sample database that you replicated into your account. It's a breeze.

secondary indexes screenshot

Technical references (including handy curl commands) run inline with each of the demos.

So long, friction

As a newb noob N00B who is developing his first application on Cloudant, it is no small comfort to me to play with live demonstrations alongside the reference material in here. Not only are the docs in-step with the product (whew), but also it's clear right away that the thing just works. And fast.

Last night, I had the Olympics on in the background as I worked on my first Cloudant-driven app. When I picked up my head to look around, prime-time coverage was long over. Kayaking was on. It was 2am.

The hours that disappeared on me weren't spent banging my simple brain against complex SQL statements, and writing and rewriting blocks of server-side code. The time was spent playing around with the data coming from my Cloudant database, moving it around the interface I'm working on. Which is a long way of saying that time flies when you're having fun.

Getting started

I went from setting up my database to playing with the interface in minutes. Here's how I got there.

Step 1 I put my data (JSON) into Cloudant with a bulk insert.

Step 2 I built my search index inside my Cloudant design doc (the same place I'll keep my secondary indexes).

{
  "_id": "design/people",
  "_rev": "13-24d8a5edfd54d61dacb0bc4230eee28a",
  "language": "javascript",
  "indexes": {
    "searchByName": {
      "index": "function(doc) {
        if(doc.docType=='person') {
          index('default', doc.last);index('default', doc.first);
        }
      }"
    }
  }
}

(My search index, searchByName, indexes the values of the first and last names of the people in my database so I can search for them by either of those or both in my application.)

Step 3 A little JavaScript to deliver it to the interface.

// Dependencies: JQuery and sag.js (http://www.saggingcouch.com/)
$(function() {
  // since I want to work locally (but use Cloudant data), I've set up a reverse proxy
  // more on reverse proxy: http://wiki.apache.org/couchdb/Apache<em>As</em>a<em>Reverse</em>Proxy
  // use sag.js to connect
  var user<em>db = 'my-Cloudant-database-name';
  var couch = sag.server('my-server'); // localhost
  couch.setDatabase(user</em>db);
  //  capture the search form submission
  $('form.search').submit(function(e){
    //  kill default action
    e.preventDefault();
    // get the value of the search input
    var query = $('#last').val();
    //  get data via sag.js
    couch.get({
      //  query my Cloudant search index (see above) and account for wildcards (partial string searches)
      url: '/design/people/search/searchByName?include_docs=true&q=' + query + '*',
      callback: function(resp, succ) {
        // vars for iterating over the results
        var rows = '', i;
        //  create the rows for my table
        for(i in resp.body.rows) {
          rows += '<tr><td>';
          rows += '<a href="#" class="view-detail data-cloudant-id="' + resp.body.rows[i].id + '">';
          rows += resp.body.rows[i].doc.first + ' ' + resp.body.rows[i].doc.last;
          rows += '</a></td></tr>';
        }
        //  drop the rows into a table and append it to the results container in my interface
        $('#results').html('<table id="people" class="table table-striped"><tbody>' + rows + ' </tbody></table>');
      }
    });
  });
});

The launch of the For Developers section is a small but important step for us. A first step toward a full-featured library of useful content for people like me and, we hope, people like you. To that end, if you're a developer using Cloudant and have ideas about docs or demos you'd like to see, please reach out. We'd love to hear from you.

Sign Up for Updates!

Recent Posts