A lightweight HTTP networking client backed by NSURLSession.
Add the following lines to your Podfile and then run pod install
.
source 'https://github.com/Originate/CocoaPods.git'
pod 'OriginateHTTP'
- iOS 8.0+
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;
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.
Log responses by listening to OriginateHTTPClientResponseNotification
. The notification will include an object conforming to <OriginateHTTPLogging>
.
OriginateHTTP is available under the MIT license. See the LICENSE file for more info.