Need help with MBRequest?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

196 Stars 15 Forks Other 131 Commits 0 Opened issues


MBRequest is a simple networking library for iOS and OS X.

Services available


Need anything else?

Contributors list

# 135,958
112 commits
# 669,277
5 commits
# 73,816
2 commits
# 418,851
1 commit
# 197,424
1 commit


MBRequest is a simple networking library for iOS and OS X. It uses a blocks-based API built on top of NSURLConnection and NSOperation. MBRequest follows the style of Apple's CLGeocoder class to create simple, easy-to-use classes that encapsulate the entire network request. The goals of MBRequest are as follows:

  • Create the simplest possible API for making network requests. With only a few lines of code, developers should be able to start a network request and pass along a single block for handling the results of that particular request.
  • Give developers an extremely simple way to create their own CLGeocoder-like classes. These subclasses should only need to set up the request and parse the response.
  • Do not force a particular implementation strategy such as singletons, "engines", or "clients". Instead, whittle the API down to the basics and let developers work with it however they wish.


MBRequest runs on iOS 5.0 and above and OS X 10.7 and above.


To include MBRequest in your applications, clone the MBRequest repository and include all of the MBRequest source files in your project.

$ git clone git://

To reference any of the functionality defined in MBRequest, simply

#import "MBRequest.h"
at the top of your source file.

Basic JSON Example

It is possible to use

to quickly grab JSON data at any URL. For example, the following code will print out the titles and authors of the top-rated YouTube videos of the past week:
NSURL *url = [NSURL URLWithString:@""];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
MBJSONRequest *jsonRequest = [[MBJSONRequest alloc] init];
[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);

Interesting Classes

If you want to incorporate MBRequest, you will likely find the following classes interesting:

To create your own requests, you will most likely want to subclass one of the above classes.

Custom Request Subclass

Even though it is possible to download JSON data directly with

(as shown in the above example), it is highly recommended that you create your own
subclass that handles the specific request for you. This will make your code more modular and much more readable (and will make your class look and act like Apple's
class). It would be silly to force everyone who wants to perform a request to understand how to setup that particular request as well as parse the data that they need out of the resulting JSON object. So, let's take the previous example and instead create an

Using this class would simplify the above example as follows:

MBRYouTubeRequest *request = [[MBRYouTubeRequest alloc] init];
[request requestTopRatedVideosFromIndex:1
                      completionHandler:^(NSArray *videos, NSError *error) {
                          if (error != nil) {
                              NSLog(@"Error: %@", error);
                          } else {
                              for (MBRVideo *video in videos) {
                                  NSLog(@"'%@' by %@", [video title], [video author]);

ARC Support

MBRequest uses ARC (Automatic Reference Counting). If you are not using ARC in your own projects, you will need to set the

compiler flag on all MBRequest files. To do this:
  1. Launch Xcode for your project.
  2. Navigate to the "Builds Phases" tab of your target(s).
  3. Find all MBRequest source files and add
    to the "Compiler Flags" column.

App Extensions

When using MBRequest in an App Extension,

to avoid using unavailable APIs. If using MBRequest in both an App Extension and a Containing App, make sure to set the
property on
in your appDelegate to
[UIApplication sharedApplication]
. Doing so will ensure that the indicator displays properly in your Containing App.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    [[MBNetworkActivityIndicatorManager sharedManager] setSharedApplication:[UIApplication sharedApplication]];




MBRequest defines a few strings that could theoretically be shown to users. These are most often error messages placed into the

dictionary of
objects. MBRequest uses the
macro to try and find translated versions of these strings for your users. This macro gives you a couple of choices if you decide to localize your application for languages other than English.
is defined as follows:
#ifdef MBRequestLocalizationTable
#define MBRequestLocalizedString(key, default) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:(default) table:MBRequestLocalizationTable]
#define MBRequestLocalizedString(key, default) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:(default) table:nil]

The first parameter of this macro is the string key while the second is the default (English) translation.

This macro allows you to add MBRequest strings directly to your standard

file. Or, if you wish, you can put all MBRequest strings into their own
file. If you opt for the latter, you must define
to be the name of this file. For example, if you want to use a file called
, you would add the following to the
file of your project:
#define MBRequestLocalizationTable @"MBRequest"

You can look for all strings used by MBRequest by searching for references to

in this project. You should see a number of hits like the following:
NSString *msg = MBRequestLocalizedString(@"request_unsuccessful_could_not_download_image", @"Request failed. Unable to download image.");

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.