Mike Meyers Mike Meyers - 1 year ago 113
Objective-C Question

Exclude some parameters with POST request on RestKit

I've just integrated RestKit with a Mac application for communicating with a web service. After much confusion, I have successfully got requests and responses working using it.

The problem I am now finding is that when I want to make a POST request.

I have created a RKRequestDescriptor with a mapping for a whole number of properties and all of the properties are being sent as parameters for the query. I want a way of dynamically changing the parameters that are sent, for example not sending some parameters where the property is nil.

Is this possible as part of the built-in functionality of RestKit? And if so, how?

Answer Source

You would need to use RestKit's Dynamic mapping class to handle mapping at run time.

Dynamic Object Mapping

RestKit supports such use cases via the RKDynamicMapping class. RKDynamicMapping is a sibling class to RKObjectMapping and can be added to RKRequestDescriptor and RKResponseDescriptor objects and used to configure RKMappingOperation instances. RKDynamicMapping allows you to hook into the mapping process and determine an appropriate concrete RKObjectMapping to use on a per-object basis.

Or you could not use RestKit and set the POST body yourself. Create the required dictionary by adding only required parameters. Serialize this object with help of NSJSONSerialization and set this NSData object as HTTP Body in the request instance.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download