/OriginateHTTP

A lightweight HTTP networking client backed by NSURLSession.

Primary LanguageObjective-CMIT LicenseMIT

OriginateHTTP

CI Status

A lightweight HTTP networking client backed by NSURLSession.

Installation with CocoaPods

Add the following lines to your Podfile and then run pod install.

source 'https://github.com/Originate/CocoaPods.git'
pod 'OriginateHTTP'

Requirements

  • iOS 8.0+

Usage

Basic HTTP

NSURL *URL = [NSURL URLWithString:@"https://www.apple.com/"];

OriginateHTTPClient *HTTPClient = [[OriginateHTTPClient alloc] initWithBaseURL:URL
                                                              authorizedObject:nil];

// perform GET on www.apple.com/robots.txt
[HTTPClient GETResource:@"robots.txt" 
               response:^(id response, NSError *error)  {
    NSLog(@"response = %@", response);
}];

Other HTTP methods are supported as well:

- (void)GETResource:(NSString *)URI
            headers:(NSDictionary *)headers
           response:(OriginateHTTPClientResponse)responseBlock;

- (void)GETResource:(NSString *)URI
           response:(OriginateHTTPClientResponse)responseBlock;

- (void)POSTResource:(NSString *)URI
             payload:(NSData *)body
            response:(OriginateHTTPClientResponse)responseBlock;

- (void)PATCHResource:(NSString *)URI
         deltaPayload:(NSData *)payload
             response:(OriginateHTTPClientResponse)responseBlock;

- (void)PUTResource:(NSString *)URI
            payload:(NSData *)payload
           response:(OriginateHTTPClientResponse)responseBlock;

- (void)DELETEResource:(NSString *)URI
              response:(OriginateHTTPClientResponse)responseBlock;

Authorization

Any additional headers necessary for authorization can be passed into the OriginateHTTPClient via an object conforming to <OriginateHTTPAuthorizedObject>.

All requests made thereafter will automatically include the appropriate headers.

Logging

Log responses by listening to OriginateHTTPClientResponseNotification. The notification will include an object conforming to <OriginateHTTPLogging>.

License

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