using loadObjectAtResourcePath on GET method, doesn’t include my parameters on the requests.
for example, if I send:
[RKObjectManager objectManagerWithBaseURL:@"http://something/ws"];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/res" delegate:self block:^(RKObjectLoader *loader) {
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
@"val", @"param1",
nil];
loader.params = [RKParams paramsWithDictionary:dict];
}];
the final url request doesn’t include the “?param1=val” part – why?
Update Months Later
The real answer is that
loader.paramscreates theHTTP BODY, hence it works forPOST, PUT, DELETEetc but not forGETwhere the params are appended to the URL.Hence, the answer below still works if you’re facing the same issue for
GET, but if you’re sending outGETrequests, it’s mostly using methods that attach the params to the query string.To summarize the differences between the two.
Sending params in the HTTP Body(i.e.
POST, UPDATE, DELETE)Caveat Emptor (for above)
Setting params in the block destroys any mapping that you might have set in
yourObject, kind of defeats the purpose of using object mapping. There’s a fix here by Sebastian loader.params – Extra params if you really want to use this method to append extra parameters to your Post not in the object.Sending in params as Query String (i.e.
GET)The rest of the answer is just for reference, I’m a hoarder.
Old Answer
I’m using RestKit for my project and facing the same issue.
I think
RKParamsis mainly used to doPOSTrequests. I cannot fully decipher your code because 1) I don’t knowloader‘s declaration? 2)RKParamsis not to be used withObject Manager?I did this.
Loader Method in App Delegate
Delegate
Output:
RK Request description: <RKRequest: 0x7993db0>and rails log say{"limit"=>"30"}.From the autocomplete in Xcode, you can see the
getrequest didn’t even useRKParams. Just aNSDict. The POST requests uses it.My goal is to attach a query string, i.e.
?location=singapore&etcetcto my API methods in Rails. For this, RK comes with aNSStringaddon calledappendQueryParamsRK docs link that you can use to append query params.If your goal is
POSTimages etc, you can follow the above line of thought of usingRKClient.Update:
If you just want to append parameters to Object Manager
This is outdated and marked for deprecation.
Use this instead:
Rails Log:
{"location"=>"latitude,longitude", "limit"=>"20"}Hope in my answer I didn’t make any wrong statements.
Refer to this question RestKit GET query parameters.