Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update Months Later</strong></p> <p>The real answer is that <code>loader.params</code> creates the <code>HTTP BODY</code>, hence it works for <code>POST, PUT, DELETE</code> etc but not for <code>GET</code> where the <strong>params are appended to the URL.</strong> </p> <p>Hence, the answer below still works if you're facing the same issue for <code>GET</code>, but if you're sending out <code>GET</code> requests, it's mostly using methods that attach the params to the query string. </p> <p>To summarize the differences between the two. </p> <p><strong>Sending params in the HTTP Body</strong>(i.e. <code>POST, UPDATE, DELETE</code>)</p> <pre><code>// Convert a NS Dictionary into Params RKParams *params = [RKParams paramsWithDictionary:optionValues]; // I use sendObject to skip the router. Otherwise it's normally postObject [[RKObjectManager sharedManager] sendObject:yourObject toResourcePath: yourResourcePath usingBlock:^(RKObjectLoader *loader) { loader.method = RKRequestMethodPOST; loader.delegate = delegate; loader.params = params; // This sets params in the POST body and discards your yourObject mapping } ]; </code></pre> <p><strong>Caveat Emptor (for above)</strong></p> <p>Setting params in the block destroys any mapping that you might have set in <code>yourObject</code>, kind of defeats the purpose of using object mapping. There's a fix here by Sebastian <a href="https://groups.google.com/d/msg/restkit/E-mQkZ-d_hY/eKZvtgQTcC0J" rel="nofollow noreferrer">loader.params - Extra params</a> if you really want to use this method to append extra parameters to your Post not in the object.</p> <p><strong>Sending in params as Query String</strong> (i.e. <code>GET</code>)</p> <pre><code>// Make a NS dictionary and use stringByAppendingQueryParameters NSDictionary *shopParams = [NSDictionary dictionaryWithKeysAndObjects: @"limit",@"20", @"location",@"latitude,longitude", nil]; [[RKObjectManager sharedManager] loadObjectsAtResourcePath:[@"/api/v1/shops.json" stringByAppendingQueryParameters:shopParams] delegate:objectDelegate]; </code></pre> <p>The rest of the answer is just for reference, I'm a hoarder.</p> <hr> <p><strong>Old Answer</strong></p> <p>I'm using RestKit for my project and facing the same issue. </p> <p>I think <code>RKParams</code> is mainly used to do <code>POST</code> requests. I cannot fully decipher your code because 1) I don't know <code>loader</code>'s declaration? 2) <code>RKParams</code> is not to be used with <code>Object Manager</code>?</p> <p>I did this. </p> <p><strong>Loader Method in App Delegate</strong></p> <pre><code>NSDictionary *shopParams = [NSDictionary dictionaryWithKeysAndObjects:@"limit",@"30", nil]; [[RKClient sharedClient] get:@"/api/v1/shops.json" queryParams:shopParams delegate:self]; </code></pre> <p><strong>Delegate</strong></p> <pre><code>- (void)requestDidStartLoad:(RKRequest *)request { NSLog(@"RK Request description: %@",[request description]); } </code></pre> <p><strong>Output</strong>: <code>RK Request description: &lt;RKRequest: 0x7993db0&gt;</code> and rails log say <code>{"limit"=&gt;"30"}</code>.</p> <p>From the autocomplete in Xcode, you can see the <code>get</code> request didn't even use <code>RKParams</code>. Just a <code>NSDict</code>. The POST requests uses it.</p> <p>My goal is to attach a query string, i.e. <code>?location=singapore&amp;etcetc</code> to my API methods in Rails. For this, RK comes with a <code>NSString</code> addon called <code>appendQueryParams</code> <a href="http://restkit.org/api/0.9.3/Categories/NSString(NSString).html#//api/name/appendQueryParams:" rel="nofollow noreferrer">RK docs link</a> that you can use to append query params. </p> <p>If your goal is <code>POST</code> images etc, you can follow the above line of thought of using <code>RKClient</code>.</p> <p><strong>Update:</strong></p> <p><strong>If you just want to append parameters to Object Manager</strong></p> <pre><code> NSDictionary *shopParams = [NSDictionary dictionaryWithKeysAndObjects: @"limit",@"20", @"location",@"latitude,longitude", nil]; </code></pre> <p><strong>This is outdated and marked for deprecation.</strong></p> <hr> <pre><code> [[RKObjectManager sharedManager] loadObjectsAtResourcePath:[@"/api/v1/shops.json" appendQueryParams:shopParams] delegate:self]; </code></pre> <hr> <p><strong>Use this instead:</strong></p> <pre><code> [[RKObjectManager sharedManager] loadObjectsAtResourcePath:[@"/api/v1/shops.json stringByAppendingQueryParameters:shopParams] delegate:yourLoaderDelegate]; </code></pre> <p><strong>Rails Log</strong>: <code>{"location"=&gt;"latitude,longitude", "limit"=&gt;"20"}</code></p> <p>Hope in my answer I didn't make any wrong statements. </p> <p>Refer to this question <a href="https://stackoverflow.com/questions/11227255/restkit-get-query-parameters">RestKit GET query parameters</a>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload