O'Reilly logo

RestKit for iOS by Taras Kalapun

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Custom HTTP client

Usually, you will use AFHTTPClient for most of the cases. However, sometimes you will need a custom one. For example, if you need to provide apikey in every request. One way would be to append it to each request just before dispatching it, but to support the DRY philosophy, we'll rewrite each request URL in a custom HTTP client class. To do so, create a subclass of AFHTTPClient as follows:

@interface MongoHqHTTPClient : AFHTTPClient @end @implementation MongoHqHTTPClient - (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters { // Consider moving API key to a more secure place NSString *apiKey = @"PUT_YOUR_API_KEY_HERE"; path = [path stringByAppendingFormat:@"?_apikey=%@", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required