Installing, Configuring, and Deploying I/O Docs

I heard about I/O Docs in a tweet from @Mashery last August. One of their evangelist developed I/O Docs with node.js and released the project on Github. I’ve wanted to check it out for two reasons. First, I have an undocumented private API – PocketBracket – that, well, I said it already, was undocumented. Second, I wanted a reason to develop with node.js.

From the I/O Docs synopsis:

I/O Docs is a live interactive documentation system for RESTful APIs

Some of the highlights of I/O Docs:

  • live and interactive
  • Promotes RESTful APIs
  • Documentation is done in JSON

Installing I/O Docs

The README within the project provides pretty good instruction for getting started with I/O Docs. It notes the changes you need to make to each file as well as full detail on how to begin documenting your API using their JSON format.

Unfortunately they gloss over the prerequisites for node.js and redis. If you’re running Mac OS X, check out my previous post on installing node.js, npm, and redis on Mac OS X. Otherwise, the links they provide should get you started.

Configuring I/O Docs

Out of the box some of the sample APIs did not run. After setting "debug": true; in config.json, I noticed these were the API requests only passing an API key. After revisiting GitHub, this was a known issue which lead me to a fork by ezarko.

I applied ezarko’s patches to app.js and config.json. This got me most of the way there. I also had to add the following to unsecuredCall() (~ line 504):

options.headers["Content-Length"] = Buffer.byteLength(options.body);

Unfortunately the DELETE requests still failed for my PocketBracket API. I realized I was expecting the API key as part of the request body. I/O Docs still appended it to the query params. For a minute I questioned my API architecture. However, using the request body for a DELETE did not violate the constraints of REST or the HTTP spec. In fact, to me, it seems more intuitive. In my opinion, only a GET request should explicitly utilize the query params.

I made a few changes to ensure DELETE requests utilized request body properly. I provide my app.js file below. So in summary, I audited the code for DELETE requests and ensured they behaved like PUT/POST (2 places). I also had to modify the if statement to ensure the request body was sent with the request (~ line 600).

Deploying I/O Docs to Heroku

While running I/O Docs locally worked, I needed to share the documentation with my team. Heroku to the rescue. Heroku is a cloud hosting service that plays nicely with git, node.js and redis. In this case, all were free add-ons. The sign up process for Heroku was simple and I was ready to deploy an app in minutes.

I started following a post about deploying I/O Docs to Heroku by Princess Ploymath. Unfortunately as noted in my comment on her post, it didn’t get me all the way. Although it ran fine locally, I received an error regarding the redis configuration when running on Heroku.

Heroku required some configuration changes in more spots than Princess Polymath noted. I added the following updates to app.js while to be minimally invasive (I hate hacking core code).

Modify the config object before creating the redis connection (~ line 60).

if (process.env.REDISTOGOURL) {
  // use production (Heroku) redis configuration
  // overwrite config to keep it simple
  var rtg = require(‘url’).parse(process.env.REDISTOGOURL);
  config.redis.port = rtg.port;
  config.redis.host = rtg.hostname;
  config.redis.password = rtg.auth.split(“:”)[1];
}

Modify the port (end of file)

//  use production (Heroku) port if set

var port = process.env.PORT || config.port;

app.listen(port, config.address);

Closing

I plan to start contributing to the I/O Docs project once I become more familiar with git/GitHub (I know). I’d like to add some additional configuration options, like passing parameters (such as the API key) in the request headers.

In the meantime, you’re welcome to download my app.js. All other changes should be configuration specific to your environment.

Installing siege on Mac OS X Lion

I am not a system admin or *nix guru. So configure-ing, make-ing, and installing applications from the command line remains intimidating. I did what most people would do – went to Google and searched for “installing siege on mac os x”. Top result looked promising. I copied step 1 to the command line. Error. Not sure if it was because the article was for Mac OS X Snow Leopard and I am on Mac OS X Lion or if I was missing a dependency the author pre-installed. Either way, if step 1 fails, it’s time to move on.

To step back, siege is an http load testing and benchmarking utility. Lately I’ve taken a strong interest in benchmarking my web applications. Mainly because I am developing APIs and using WordPress (which is notorious for being slow under server load). Although ab (Apache Benchmark) comes bundled with apache (which is preinstalled on Mac OS X), I’ve been hearing a lot about siege at conferences. As any good developer should, I wanted to tinker with it myself.

Installing siege

  1. Open the Terminal app
  2. Download the latest version of siege (currently 2.70)
    curl -C - -O http://www.joedog.org/pub/siege/siege-latest.tar.gz
  3. Extract the tarball
    tar -xvf siege-latest.tar.gz
  4. Change directories to the extracted directory (again, currently siege-2.70)
    cd siege-2.70/
  5. Run the following commands (one at a time) to build and install siege. If you have an older version of siege read the INSTALL file for more instructions.
    ./configure
    make
    make install

This installed siege to /usr/local/bin/. This should already be in your PATH, so type:

siege 

You will be presented with a message that instructs you to generate a siege configuration file for your account.

siege.config 

Now you can run siege. The following sends a 10 requests across 10 concurrent connections for benchmarking (no delay between requests).

siege -c 10 -r 10 -b http://jason.pureconcepts.net/ 

If you want to learn more about configuring or using siege type siege -h or visit the siege manual.

CSS Organizer and Minifier

The Problem

During the development process I may have several CSS files containing all sorts of rules. These names may be based by page or the general rules contained in each file. However, in production, from both a maintainability and performance perspective, the last thing you want is several files. Ideally, you would like a single, compact CSS file for production. If usings themes, you may want more. So between development and production, you want two very different things.

The Proposed Solution

Normally, when one needs to go from a raw material to a finished products, a tool is used. In this case, I need something that can process my CSS files between development and production. Maybe it can also do some additional items during processing, like code formatting, file organization, or minification. I did not find such a tool that existed. So I have undertaken this project to develop such a tool.

With any tool there are guidelines or a practice. You wouldn’t use a chainsaw while building a dollhouse. So even though this will not fit the need, my hope is that this tool will nonetheless help.

Project Specification

I know we are all different, which makes this project near impossible. I have done the best to accommodate that into this spec. Nonetheless, with every tool there are guidelines. I mean you wouldn’t use a chainsaw while building a dollhouse. My hope is that by adopting a few industry conventions, and drawing some lines, this tool will help a maximum audience.

  • Accept CSS files
    • files can be within directories
    • ability to provide file cascade manually or automatically from convention
  • Process CSS files
    • categorize declarations into three groups: layout, typography, and style
    • output categorized CSS into repectively named files
  • Miscellaneous
    • validation
    • simple formatting options
    • simple minification options: whitespace, shorthands, duplication

In Closing

I have begun an alpha version following the above spec in Java. My goal is to create a proof of concept and use it during a project before releasing a web version on this site. However, you requests are required. So please, post comments or send me feedback directly.