0

How do I send parameters with RKRequestMethodDELETE request. I need to send groupId (INT) and users (an array).

Below is the code that I'm using and it's appending it to the URL:

https://www.domain.com/g/members?groupId=15&users[][userId]=john.doe

Instead I would like to send the request to:

https://www.domain.com/g/members

and have groudId and users array as part of the request as parameters.

I need to send

{
    [self newObjectManager];
    [self refreshMOC];

    RKEntityMapping *groupMapping = [RKEntityMapping mappingForEntityForName:kEntityGroup inManagedObjectStore:self.objectManager.managedObjectStore];
    groupMapping = [TBSRESTMappingProvider groupGetMapping:groupMapping];

    NSIndexSet *statusCodeSet = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:groupMapping
                                                                                            method:RKRequestMethodDELETE
                                                                                       pathPattern:kPathPOSTGroupMembers
                                                                                           keyPath:nil
                                                                                       statusCodes:statusCodeSet];

    NSArray *stringMembers = [self NSStringMembersFromFriendObjects:members];

    NSMutableURLRequest *request = [self.objectManager.HTTPClient requestWithMethod:kRequestMethodDELETE
                                                                               path:kPathPOSTGroupMembers
                                                                         parameters:@{ @"groupId": group.groupId,
                                                                                       @"users" : stringMembers }];

    [self.objectManager.HTTPClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];

    RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
    operation.managedObjectContext = self.objectManager.managedObjectStore.mainQueueManagedObjectContext;
    operation.managedObjectCache = self.objectManager.managedObjectStore.managedObjectCache;

    [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

    } failure:^(RKObjectRequestOperation *operation, NSError *error) {

    [operation start];
}
Wain
  • 118,658
  • 15
  • 128
  • 151
user1107173
  • 10,334
  • 16
  • 72
  • 117
  • 1
    What is this additional info? Is it related to a single object? Or you're trying to delete multiple objects? Why aren't you using the object manager DELETE interface? – Wain Sep 30 '14 at 13:01
  • The server requires additional info contained in the array to delete multiple objects. Object manager DELETE interface? Do you mean: deleteObject:path:parameters:success:failure: method? Is there a method with object manager to delete multiple object? – user1107173 Sep 30 '14 at 15:30
  • 1
    You can try passing an array of objects, or passing it a dictionary containing an array and have either of those encoded to JSON... – Wain Sep 30 '14 at 16:57
  • Using RKManagedObjectRequestOperation? I think that's what I'm doing in the code above, no? `users` is an array. Can you please provide an example as an answer? Thanks! – user1107173 Sep 30 '14 at 17:11
  • When you have a minute can you please answe this. I'm stuck! Thanks. – user1107173 Oct 02 '14 at 11:09
  • You don't use `RKManagedObjectRequestOperation` if you use the object manager interface. I haven't tried it before (so I don't know if it encodes the object to JSON), but did you pass an array of objects? By using `RKManagedObjectRequestOperation` direct with a request you are skipping all JSON related processing... – Wain Oct 02 '14 at 11:39
  • If I use 'POST' instead of 'DELETE' JSON seems to be included in the request. It's something with 'DELETE'. – user1107173 Oct 02 '14 at 13:17

0 Answers0