22 May 2013
The one about how networking 2.0 happened
A few months ago, I talked about networking 2.0, but what I didn’t mention was that the driving force behind these improvements was the Corona community’s own Bob Dickinson.
For awhile, Bob was pretty vocal about some of the shortcomings of the old network 1.0 stack, and made that clear in his bug reports where he expressed his frustration. He’d say things that were brutal like “Network request/download support is only suitable for toy apps,” but balance those comments with constructive thoughts about improvements he’d like to see.
Over an e-mail exchange, it turns out that Bob really wanted to make something happen:
What I would like to do is volunteer to rework the Corona networking APIs (specifically network.request and network.download) in order to both address the specific open bugs, and also to extend the APIs and make them more robust, as outlined in 14023. I think that this can be done without changing the API definitions (so the new implementations would be fully backward compatible and pass any current unit tests).
So after several conversations, we agreed to give it a go! One of my primary concerns was the API, and Bob was (thankfully) patient as I poured over every detail of the API changes. We’ve had several dozens of exchanges just on the API. We covered a bunch of things including error handling, distinguishing between text/binary in responses, and minutiae like how download file paths should be specified.
Here’s a typical example of the kind of exchange we had. In this one, we decided on the name for a new API to cancel http requests:
I went back and forth. I picked cancelRequest( ) because, unlike the
timer module, the network module has a couple of methods that deal
with things that you might think are cancelable and that are not
requests (the network status functions). But I’m fine either way.
I have slight preference for the more succinct “network.cancel()”, so let’s go with that.
Then came development. Bob rewrote the Android implementation because a newer HttpURLConnection had become available since the time at which we wrote the original. He then ported over our existing iOS, Mac, and Windows implementations.
Given the number of platforms involved, it was definitely a significant undertaking and a Herculean effort by Bob. I could go on about all the technical details but long story short, we all have a richer set of http APIs.
Thanks Bob for all your hard work, generosity, and dedication. Corona is that much better for it!