Search code examples
objective-crestful-urlrestful-architecture

RESTFull Architecture HTTP GET & PUT Requests


Could anybody point me to a tutorial, examples or docs about http request, GET, PUT.

I need to put & get a JSON package to & from a URL.

Cant find much objective-c information about receiving JSONs from a HTTP request.

Any help is appreciated.


Solution

  • Using AFnetworking Would best Idea.

    here is the following example.

     NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:emailUITextView.text, @"email",  passwordUITextView.text,@"password",  customerType,@"usertype", nil];
        NSURL *url = [NSURL URLWithString: BASE_URL];
        AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
    
        [httpClient postPath:@"/sign_in" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSLog(@"Success : %@", operation.responseString);
            if([operation.responseString isEqualToString:@"true"])
                NSLog(@"Signed In successfully");         
            else if ([operation.responseString isEqualToString:@"false"])
                NSLog(@"Signed In unsuccessfully");
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"Failure : %@", error);
            UIAlertView *alert = [[ UIAlertView alloc]initWithTitle:@"Error" message:[error localizedDescription] delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
            [alert show];
        }];