Latest 1.1.3
Homepage https://github.com/JamieREvans/NetworkSimple
License MIT
Platforms ios 6.0, osx 10.8, requires ARC
Dependencies NSJSONSerialization-NSNullRemoval, Reachability
Authors

CI Status
Version
License
Platform
Coverage Status

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

NetworkSimple is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "NetworkSimple"

How to Use

To use the library, start by importing the client

#import <NetworkSimple/NSClient.h>

To use the client, you’ll have to start out with an instance

NSClient *client = [NSClient clientWithScheme:@"http" andHost:@"randomuser.me"];

To make a simple URL request, you can perform the following

[client sendRequestWithEndpoint:@""
                 httpMethodType:NSHTTPMethodTypeGet
                    requestType:NSRequestTypeURL
                     dataObject:nil
           requestMutationBlock:nil
                    andCallback:^(NSUInteger statusCode, id responseObject, NSError *error)
 {
     if(statusCode == 200)
     {
         // Received users!
         // responseObject should contain an NSArray of user objects
     }
     else if(error)
     {
         // Display alert with error message
     }
 }];

For a more complicated request, lets send a POST request with JSON body data. We’ll also set an HTTP header in the requestMutationBlock – this is always fired last in the request generation.

[client sendRequestWithEndpoint:@""
                 httpMethodType:NSHTTPMethodTypePost
                    requestType:NSRequestTypeJSON
                     dataObject:@{@"firstName"   : @"Jamie",
                                  @"lastName"    : @"Evans",
                                  @"phoneNumber" : @"555-555-5555"}
           requestMutationBlock:^(NSMutableURLRequest *request)
 {
     [request setValue:@"cbeiqu829fPamfr12adkjln" forHTTPHeaderField:@"client_token"];
     [request setTimeoutInterval:10.0f];
 }
                    andCallback:^(NSUInteger statusCode, id responseObject, NSError *error)
 {
     if(statusCode == 200)
     {
         // Created a user successfully!
     }
     else if(error)
     {
         // Failed to create a user :(
     }
}];

We can also update the default timeout intervals for our requests

[client setRequestTimeout:10.0f];

Or set the request caching policy

[client setCachingPolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData];

And if you’re using multipart requests, you’ll want to set the boundary string

[client setBoundaryString:@"myBoundaryStringForThisApplication"];

All of these properties can be overridden in the requestMutationBlock.

Author

Jamie Evans, [email protected]

License

NetworkSimple is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "NetworkSimple",
    "version": "1.1.3",
    "summary": "Simplifying all network requests",
    "homepage": "https://github.com/JamieREvans/NetworkSimple",
    "license": "MIT",
    "authors": {
        "Jamie Evans": "[email protected]"
    },
    "source": {
        "git": "https://github.com/JamieREvans/NetworkSimple.git",
        "tag": "1.1.3"
    },
    "platforms": {
        "ios": "6.0",
        "osx": "10.8"
    },
    "requires_arc": true,
    "dependencies": {
        "NSJSONSerialization-NSNullRemoval": [
            "~> 1.0"
        ],
        "Reachability": [
            "~> 3.2"
        ]
    },
    "source_files": "Pod/Classes"
}

Pin It on Pinterest

Share This