3

I'm trying to send a simple request with RestKit, I'm interested only in getting the JSON,

here are my codes:

NSURL *endpoint = [NSURL URLWithString:@"https://www.ez-point.com/api/v1/"];
    RKObjectManager* objectManager = [RKObjectManager managerWithBaseURL:endpoint];
    [objectManager.HTTPClient setAuthorizationHeaderWithToken:@"xxxxxxxxxxx"];
    [objectManager getObjectsAtPath:@"ezpoints" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        NSLog(@"It works");
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        NSLog(@"Request failed");
    }];

the Error I'm getting is:

    Restkit.network:RKObjectRequestOperation.m:243 GET 
    'https://www.ez-point.com/api/v1/ezpoints' (200 OK / 0 objects) 
    [request=0.0000s mapping=0.0000s total=1.6094s]: Error 
Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x160df470 {NSErrorFailingURLStringKey=https://www.ez-point.com/api/v1/ezpoints, 
    NSLocalizedFailureReason=A 200 response was loaded from the URL 'https://www.ez-point.com/api/v1/ezpoints', which failed to match all (0) response 
    descriptors:, NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=https://www.ez-point.com/api/v1/ezpoints, NSUnderlyingError=0x160a9730 "No mappable object representations were found at the key paths searched."}
        2013-10-28 15:03:40.899 EZ-POINT[1651:c07] Request failed

Any idea about this problem?

Wain
  • 118,658
  • 15
  • 128
  • 151
Noor
  • 19,638
  • 38
  • 136
  • 254

2 Answers2

5

As the error says, RestKit could not find any response descriptors for the loaded response. That's because you did not set up any.

If you just want to load JSON without mapping it, RestKit could be a bit over the top and you should place your bet on AFNetworking that is also used by RestKit:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];
tilo
  • 14,009
  • 6
  • 68
  • 85
  • The issue is that I only need the JSON, how can I retrieve the JSON from the response? I don't need any mapping, is it possible to retrieve the plain json using Restkit – Noor Oct 28 '13 at 11:12
  • RestKit makes use of AFNetworking. See my edited answer for an example @user1774937 – tilo Oct 28 '13 at 12:12
3

If your interest is:

only in getting the JSON

then you shouldn't be using RestKit - that isn't what it's for. Instead, use AFNetworking (which is included with RestKit so you have access to use both).

Use the correct tool for the job...

Wain
  • 118,658
  • 15
  • 128
  • 151