How to Make REST api call in Objective-C.

We can call using this.
NSString *twitterUrl = @"YourUrlString";
NSString *resp = [self makeRestAPICall: twitterUrl];
and method is
-(NSString*) makeRestAPICall : (NSString*) reqURLStr
{
    NSURLRequest *Request = [NSURLRequest requestWithURL:[NSURL URLWithString: reqURLStr]];
    NSURLResponse *resp = nil;
    NSError *error = nil;
    NSData *response = [NSURLConnection sendSynchronousRequest: Request returningResponse: &resp error: &error];
    NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
    NSLog(@"%@",responseString);
    return responseString;
}

Comments

  1. Nice post with great details. I really appreciate your idea. Thanks for sharing.
    --------------------------------------------------------------------------------------------------------------
    iPhone App Development & iOS App Development & Android Application Development

    ReplyDelete
  2. Thank you so much for throwing light on such an important aspect of REST API.

    SQL Server Load Rest Api

    ReplyDelete

Post a Comment

Popular posts from this blog

Launch iPhone simulator without Xcode.

id vs NSObject