I'm using RestKit and I'm trying to post an object with a query parameter (an auth token in the form of token=<token>), but I can't figure out how to get it to work. Here's what I'm doing...
First, I add the request object mapping to the manager:
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
[requestMapping addAttributeMappingsFromDictionary:@{
@"id" : @"id",
@"name" : @"name",
@"latitude" : @"latitude",
@"longitude" : @"longitude"
}];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[Location class] rootKeyPath:nil];
[manager addRequestDescriptor:requestDescriptor];
Then I make the request:
RKManagedObjectRequestOperation *operation = [RKObjectManager.sharedManager appropriateObjectRequestOperationWithObject:self method:RKRequestMethodPOST path:@"/api/v1/users/3/locations" parameters:@{@"token" : token}];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
Location * location = (Location*)mappingResult;
self.id = Location.id;
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
ALog(@"fail!");
}];
[RKObjectManager.sharedManager enqueueObjectRequestOperation:operation];
When the request is made, the Location object is serialized to JSON and put in the request body just fine. However, instead of the token being added to the query string, it is added as JSON to the request body.
Example:
request.body={"id":0,name="test","longitude":-0.1337,"latitude":51.50998,"token":"Z3JlZ2c6MTM2MDU2OTk2MDY2OTpMajkxd01acWxjcGg1dEpFVy9IaEcwNTcyMWJkSEpnTFRTQTI2eXNlN29VOVRTc1UwV1lEU0E9PQ=="}
Any help is greatly appreciated!