Search code examples
iosobjective-crestkit

Using RestKit un-restfully


Is there any way to use RestKit in an unrestful way?

For example, If I set up an object mapping as such:

[manager.router routeClass:[BBMediaResourceCreate class] 
            toResourcePath:@"/mediaresources" 
                 forMethod:RKRequestMethodPOST];

RestKit will expect that I post a BBMediaResourceCreate object and receive one back also.

My API however, for reasons I won't go into, is not RESTful compliant in some situations. Rather than receive the newly created resource, I'll get something more like:

{ Model: { Success:true} } 

or something similar

Is there a way to map a RestKit post to post a resource of one type but expect a response of another type?


Solution

  • When using v0.10 you can simply set resourcePath:@"/"and respond to

    - (void)objectLoaderDidLoadUnexpectedResponse:(RKObjectLoader *)objectLoader

    or

    - (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObject:(id)object

    and handle the response in [objectLoader response] like you want. Keep in mind that posting to that resource then needs an explicit, manually set path.