tweet @echoz email jeremy@ornyx.net
Have been very much inspired by the work on nodejs. For those of you who don’t know, nodejs is a basically a system to do Evented I/O using Google’s V8 Javascript engine.
One such application of nodejs is the development of servers both HTTP or socket based that doesn’t require the spinning up of threads to handle connections and/or network events. Callbacks are assigned to events and when those events happen, the callbacks are ran. No threads, easy peasey, low overheads, etc.
Currently there are 2 ways to do NSURLRequests. You can either wrap it around a thread and execute the operation synchronously or implement its delegate methods and have it run within the runloop.
JOURLRequest is an encapsulation of the NSURLRequest and its delegate methods to provide for a way to easily implement run loop based event-ed NSURLRequests. In addition to handling the delegate methods and providing its own, it also implements a blocks based system on top of the delegate methods to make development easier for developers who already know blocks.
The class also takes into account authentication via blocks or delegate methods to provide the right response to such situations. So its kinda event-ed in its own right.
If deployed on an iOS project, it also handles situations where network reachability is dropped as well as handle when apps go into background or return from foreground and return statuses accordingly.
It also provides static methods to create NSURLRequests based upon a dictionary of POST values. By default, if it detects a NSData within the dictionary, it’ll assume its a file upload and prepare the URLRequests accordingly. If not, it will use the less network intensive x-www-form-urlencoded method.
I’ve started using it for projects and the experience thus far is one of more responsive applications with lesser pains when it comes to dealing with events. (Blocks for the win!)
Its still very much a work in progress, but the bulk of it is there and working. Using it is simply including the files in your project and including the headers where you want to use this class.
Todo:
So I wrote some code.