Today, I was at Hack Dev days in Vancouver, B.C. and enjoyed the group and the presentations. Two recent Uni-grads and I teamed up and proceeded to define a project and work away for most of the day. We were using the TinEye.com API, specifically a collection of 10 million images from Flickr that they have in one of their libraries. We decided to create a Chrome Extension on the API (one of the other dev’s had done one of these recently).
The code that consumed most of the day…
The code below should have been up and working in 15 minutes…
The problem was that the status was a zero(0) with no status message. Googling XMLHttpRequest and zero status code found many pages describing a similar issue but no clear explanation (or solution). I installed the latest version of Fiddler Web Debugger, and saw that the call went off fine, and that the service returned the appropriate JSON fine.
So the call to the API was being correctly done, results were coming back but with a bizarre status code of zero. Asking around the local HACK developers and no one had an answer…. So it was off trying to find a solution, including trying $.ajax () – which provided less information, overriding mime types, changing “POST” to various other REST verbs (GET was rejected by the API)… the typical systematic trying every variation that came to mind. My colleagues were also encountering problems that they could not identify the cause ….
Well, finally the light went on (I was the one that realize the issue), we were trying to do cross domain POSTs. It turned out that their obtuse problems were the same issue.
In hind-sight, the waste of time could have been avoided if:
- There was a statusText message that went with the zero status code (i.e. “Security violation – cross domain post”), or
- The .send() raised an error message….
- Seeing the data coming back in Fiddler, lead me down the wrong path – the API appear to be working correctly…
- The TinEye.com documentation had reminded the reader about the cross-domain posting issue
- Ideally, the documentation would have sample code on how to create the needed component on your own server in all of the common languages. Having the code ready to cut-and-paste would have improved adoption
- Personally, I would love to see firms providing API’s contract out to a seasoned technical developer engineer (what I use to be called at Microsoft) who is good at:
- Technical writing
- Creating non-trivial engineering code examples that goes the “extra mile” (resulting in faster adoption of the API).
- Anticipating how novice developers are likely to proceed and making them successful!
- The Facebook API is THE classic example of how not to do API documentation.
- I (or my fellow hacks) had bumped up against the cross-domain API post issues recently.
That’s it for today’s RANT…