Nice Simple Objective-C Networking Library With A Blocks based API

I’ve mentioned some great libraries for networking such as the popular MKnetworkKit, and AFNetworking which are great full featured networking libraries.

Today I came across a very interesting library providing a blocks based API using NSURL and NSConnection and built in the style of Apple’s CLGeocoder class.

What’s nice about this library is the simplicity, and that you are not forced to use a specific style.  The library also provides some extras for JSON and localization.

Here’s a basic JSON request taken from the readme:

NSURL *url = [NSURL URLWithString:@"https://gdata.youtube.com/feeds/api/standardfeeds/top_rated?alt=json?time=this_week"];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
MBJSONRequest *jsonRequest = [[[MBJSONRequest alloc] init] autorelease];
[jsonRequest performJSONRequest:urlRequest completionHandler:^(id responseJSON, NSError *error) {
if (error != nil)
{
NSLog(@"Error requesting top-rated videos: %@", error);
}
else
{
NSArray *videos = [[responseJSON objectForKey:@"feed"] objectForKey:@"entry"];
for (NSDictionary *videoInfo in videos)
{
NSString *title = [[videoInfo objectForKey:@"title"] objectForKey:@"$t"];
NSString *author = [[[[videoInfo objectForKey:@"author"] objectAtIndex:0] objectForKey:@"name"] objectForKey:@"$t"];
NSLog(@"’%@’ by %@", title, author);
}
}
}];

The library is MBRequest from Mobiata and can be found on Github here along with full usage instructions.

A nice choice if you’re looking for a simple networking library.

©2012 iPhone, iOS 5, iPad SDK Development Tutorial and Programming Tips. All Rights Reserved.

.

DeliciousTwitterFacebookLinkedInEmail


Leave a Reply

Your email address will not be published. Required fields are marked *