Moving away from ASIHTTPRequest

Moving away from ASIHTTPRequest

As most of you already know, the ASIHTTPRequest library is no longer being maintained. You could either write your own framework, which probably takes a lot of time to completely configure to your needs, or use a different library.
In my latest project I started using the AFNetworking library, and it turns out to be a really great library!

So what are the differences, and why should you switch?

AFNetworking is a fully supported library, with updates available every 2 weeks at least and a very stable community support.

I made it easy for myself to call webservices with either GET or POST, below you'll find the code to do so. As the library uses blocks, it's easy to pass information through aswell.

-(void)commandWithParams:(NSMutableDictionary *)params forPath:(NSString *)path onCompletion:(JSONResponseBlock)completionBlock andMethod:(NSString *)method{
    NSMutableURLRequest *apiRequest = [self requestWithMethod:method path:path parameters:params];
    
    AFJSONRequestOperation* operation = [[AFJSONRequestOperation alloc] initWithRequest: apiRequest];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        //success!
        completionBlock(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        //failure :(
        completionBlock([NSDictionary dictionaryWithObject:[operation responseString] ? [operation responseString]  : [error localizedDescription] forKey:@"error"]);
    }];
    
    [operation start];
}

-(void)getWithParams:(NSMutableDictionary*)params forPath:(NSString *)path onCompletion:(JSONResponseBlock)completionBlock {
    [self commandWithParams:params forPath:path onCompletion:completionBlock andMethod:@"GET"];
}

-(void)postWithParams:(NSMutableDictionary*)params forPath:(NSString *)path onCompletion:(JSONResponseBlock)completionBlock
{
    [self commandWithParams:params forPath:path onCompletion:completionBlock andMethod:@"POST"];
}

Their github is very well documented and contains all the necessary steps to take into calling your first web-service. Be sure to check it out!

https://github.com/AFNetworking/AFNetworking

If you have any questions, be sure to drop a comment.
Thanks for reading,
Nikki