Relaxing with CouchApp part 1

I have an epic nerd-boner for non-relational databases, so when I ran across CouchApp on Hacker News the other day I had to give it a go.

A CouchApp is a web application built directly on top of Apache CouchDB - because the database talks HTTP natively, apps can be set up to be served direct to the browser, with none of that tedious mucking about in application layers. The details are explained pretty well in What the HTTP is CouchApp?

So, now that you know what I’m talking about, what the HTTP am I planning to DO with CouchApp? Well, I’ve got a few ideas in the pipeline once I’ve got the hang of it, but for now I was thinking it might be fun to get a quick and dirty clone of the beercave site up and running.

The now traditional tedious “Getting Started” bit”

This wouldn’t be a proper development article without a laborious description of how to get up and running, now would it. Fortunately, it’s not very difficult. So here goes.

Things you’ll need before you start

  • Python - 2.5 or later
  • setuptools - sure, you could manually install the couchapp scripts, but why would you want to?

Go install those and come back. I’ll wait.

Things you’ll need to get started

  • CouchDB - I’ve played with the Windows and Mac builds and they were both incredibly painless to get running. Download, unzip & run and you have your own database instance right there. A far cry from your standard Open Source scenario of “download these exact versions of 123 different packages and build them from source or fuck off, noob!”
  • Some sort of text editor would probably come in handy ;) I use Notepad++ on windows. If you like something else, use that instead. If you try and embroil me in a vim vs. emacs war I will kill you with knives. Large, shiny knives. I have several…

The Install

Unzip the CouchDB binaries somwhere you’ll find them again and start it up. C:\Program Files\CouchDB would be a good choice for Windows types, Mac users might want to try the Applications folder.If you’re installing from source, you probably know what you’re doing, so go to it.

Pop open a command window and install the CouchApp scripts:

easy_install couchapp

Now create yourself a shiny new CouchApp!

C:\DevSoftware\projects>couchapp generate beercave
2010-08-05 19:17:38 [INFO] C:\DevSoftware\projects\beercave generated.

This generates you the skeleton of your new CouchApp.
If you set up an admin account on your CouchDB, now’s the time to fill in its details in the new .couchapprc file

{
"env": { 
"default": {
  "db": "http://username:password@localhost:5984/beercave"
}
}
}

Now that that’s done, just publish your new CouchApp to CouchDB.

C:\DevSoftware\projects\beercave>couchapp push
2010-08-05 20:11:33 [INFO] Visit your CouchApp here:
http://localhost:5984/beercave/_design/beercave/index.html

Now just follow the link and you should see something like this:
Photobucket
Not much like the beercave site yet, but we’ll get to that.