Using REST Request Methods
Salesforce offers some product-specific REST APIs that have no relationship to Salesforce Platform APIs. You can use Mobile SDK resources to configure and send such requests. For these cases, you create and configure your RestRequest
object directly, instead of relying on factory methods.
To send a non-SOQL and non-SOSL REST request using RestClient
:
-
Create an instance of
RestRequest
. -
Set the properties you need on the
RestRequest
object. -
Call
send
on theRestClient
object, passing in theRestRequest
object you created as the first parameter.The following example performs a GET operation to obtain all items in a specific Chatter feed.
-
To perform a request with parameters, wrap your parameter string using
SFJsonUtils.object(fromJSONString:)
, and assign it to thequeryParams
property ofRestRequest
. To send a custom request, create aDictionary
object and use thesetCustomRequestBodyData(_:contentType:)
method ofRestRequest
.The following example uses a custom request body to add a comment to a Chatter feed.
-
To set an HTTP header for your request, use the
setHeaderValue(_:forHeaderName:)
method. This method can help you when you’re displaying Chatter feeds, which come pre-encoded for HTML display. To avoid displaying unwanted escape sequences in Chatter comments, set theX-Chatter-Entity-Encoding
header of your request to “false”: