Question

I'm working with an API that only has POST calls. Create, edit, and delete. This is causing some problems with RestKit for editing and deleting.

Create works as expected. However, when I make an edit to an object it's not saved to my device until I call a GET request again (that's working as well). I'm assuming it's because I'm not calling patchObject and deleteObject (instead I have to use postObject) and there is some Core Data magic happening in the background.

They API will be updated in the near future, but in the man time is there a way to trick the object manager to handle my POST requests differently?

Was it helpful?

Solution

This won't be fun for you since RestKit adhere 100% to the REST concept. take a look at the code of RKObjectManager (here is the implementation). RKObjectManager is made to be subclassed, but I know Blake, the creator of RestKit, do a lot of conditioning depending of the type of the request sent, so tricking them to all POST looks dangerous to me.

What you could do is still using all the postObject:, deleteObject:, patchObject:, etc. from RestKit but trick the call RK do to AFNetworking (the HTTPClient underlayer) to all POST.

Take a look at - (NSMutableURLRequest *)requestWithMethod:path:parameters: in RKObjectManager.

Hope this help somehow!

OTHER TIPS

You should use PATCH for update and DELETE for delete directly instead of calling POST for both operations.

RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://restkit.org"];
[manager addRequestDescriptor:requestDescriptor];
[manager addResponseDescriptor:responseDescriptor];

// POST to create
[manager postObject:article path:@"/articles" parameters:nil success:nil failure:nil];

// PATCH to update
article.body = @"New Body";
[manager patchObject:article path:@"/articles/1234" parameters:nil success:nil failure:nil];

// DELETE to destroy
[manager deleteObject:article path:@"/articles/1234" parameters:nil success:nil failure:nil];

Check this link from the new RestKit Docs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top