ios - Making HTTP Requests API Calls -


i have following code in ios sdk building:

+ (void) makerequesttoendpoint:(nsstring *) endpoint values:(nsmutabledictionary *) params oncompletion:(sdkcompletionblock) responsehandler {     [params setobject: key forkey: @"key"];      nsstring * urlstring = [self createapiurlfromendpoint: endpoint];     nsurl * url = [nsurl urlwithstring: urlstring];      nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl: url];     request.httpmethod = @"post";     [request setvalue:@"application/json" forhttpheaderfield:@"accept"];     [request setvalue:@"charset" forhttpheaderfield:@"utf-8"];     [request setvalue:@"application/json" forhttpheaderfield:@"content-type"];     request.httpbody = [[params urlencodedstring] datausingencoding:nsutf8stringencoding];      [nsurlconnection sendasynchronousrequest:request                                        queue:[nsoperationqueue mainqueue]                            completionhandler:^(nsurlresponse *response, nsdata *data, nserror *error)     {          nserror * dicerror = nil;         nsdictionary * dictionary = nil;          if([data length] >= 1) {             dictionary = [nsjsonserialization jsonobjectwithdata: data options:kniloptions error: &dicerror];         }          responsehandler(dictionary, error);     }];  } 

so people using sdk can make api calls doing following:

[sdk makerequesttoendpoint: @]

what best way structure (best way handle error handling, response handling, etc) code above make easy people use sdk?

there many open source frameworks can learn design practices asynchronous networking. recommend take at


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -