Mapping actual parentheses in resources paths

44 views
Skip to first unread message

Nick Curran

unread,
Jun 24, 2012, 10:41:35 AM6/24/12
to res...@googlegroups.com
I'm trying to map PUTs and DELETEs to OData resource paths. OData address resources with actual parentheses, like so:

/Thing(23)

Is there a way to route this in RestKit? Currently the parentheses get stripped out and I end up with

/Thing:23


I have a workaround where I route with [ and ] instead of ( and ), and then I replace those in requestWillPrepareForSend, but that solution smells. I'd like to be able to escape the parentheses somehow and move on.

My setup:

[objectManager.router routeClass: [Thing class] toResourcePath: @"/Thing(:id)" forMethod: RKRequestMethodPUT];
[objectManager.router routeClass: [Thing class] toResourcePath: @"/Thing(:id)/" forMethod: RKRequestMethodDELETE];

Mark Peters

unread,
Nov 9, 2012, 3:51:52 PM11/9/12
to res...@googlegroups.com
Hi Nick
 
Did you ever solve this? I'm running into the same issue and can't seem to find an elegant way out.
 
Thanks
Mark

Nick Curran

unread,
Nov 9, 2012, 3:58:22 PM11/9/12
to res...@googlegroups.com
I solved it with a kludge. It's not ideal, but it works. I used [] instead of () in my routing, and then I handle requestWillPrepareForSend: in my RKRequestDelegate to convert them on the actual send. 

#pragma mark - RKRequestDelegate

- (void) requestWillPrepareForSend: (RKRequest*) request
{
    NSRange range = [request.resourcePath rangeOfString: @"["];
    if (range.location == NSNotFound)
        return;
    id params = request.params;
    NSString* path = [request.resourcePath stringByReplacingOccurrencesOfString: @"[" withString: @"("];
    path = [path stringByReplacingOccurrencesOfString: @"]" withString: @")"];
    request.resourcePath = path;
    request.params       = params;
}

Blake Watters

unread,
Dec 17, 2012, 9:03:56 PM12/17/12
to res...@googlegroups.com
Parentheses matching/replacement is no longer performed under 0.20.
Reply all
Reply to author
Forward
0 new messages