SFRestRequest Class Reference

Inherits from NSObject
Declared in SFRestRequest.h

Overview

Request object used to send a REST request to Salesforce.com

Other Methods

  method

The HTTP method of the request. See SFRestMethod.

@property (nonatomic, assign, readwrite) SFRestMethod method

Declared In

SFRestRequest.h

  networkServiceType

The HTTP method of the request. See SFRestMethod.

@property (nonatomic, assign, readwrite) SFSDKNetworkServiceType networkServiceType

Declared In

SFRestRequest.h

  serviceHostType

The type of service host for the request (e.g. login or instance).

@property (nonatomic, assign, readwrite) SFSDKRestServiceHostType serviceHostType

Declared In

SFRestRequest.h

  sessionDataTask

The NSURLSesssionDataTask instance associated with the request. This is set only once the request is queued and could be ‘nil’ before that happens.

@property (nullable, nonatomic, strong, readwrite) NSURLSessionDataTask *sessionDataTask

Declared In

SFRestRequest.h

  baseURL

The base URL of the request, to be prepended to the value of the path property. By default, this will be the API URL associated with the current user’s account. One use would be when in a community setting and you want to send a request against the base API URL.

@property (nullable, nonatomic, strong, readwrite) NSString *baseURL

Declared In

SFRestRequest.h

  path

The path of the request or the full URL to be used. If a full URL is passed in, the endpoint ceases to matter. For instance, “” (empty string), “v22.0/recent”, “v22.0/query”. Note that the path doesn’t have to start with a ‘/’. For instance, passing “v22.0/recent” is the same as passing “/v22.0/recent”.

@property (nonnull, nonatomic, strong, readwrite) NSString *path

Discussion

Warning: Do not pass URL encoded query parameters in the path. Use the queryParams property instead.

Declared In

SFRestRequest.h

  parseResponse

Used to specify if the response should be parsed. YES by default.

@property (nonatomic, assign) BOOL parseResponse

Declared In

SFRestRequest.h

  queryParams

The query parameters of the request (could be nil). Note that URL encoding of the parameters will automatically happen when the request is sent.

@property (nullable, nonatomic, strong, readwrite) NSMutableDictionary<NSString*id> *queryParams

Declared In

SFRestRequest.h

  customHeaders

Dictionary of any custom HTTP headers you wish to add to your request. You can also use setHeaderValue:forHeaderName: to add headers to this property.

@property (nullable, nonatomic, strong, readwrite) NSMutableDictionary<NSString*NSString*> *customHeaders

Declared In

SFRestRequest.h

  requestDelegate

The delegate for this request. Notified of request status.

@property (nullable, nonatomic, weak) id<SFRestRequestDelegate> requestDelegate

Declared In

SFRestRequest.h

  endpoint

Typically kSFDefaultRestEndpoint but you may use eg custom Apex endpoints

@property (nonnull, nonatomic, strong, readwrite) NSString *endpoint

Declared In

SFRestRequest.h

  requiresAuthentication

Whether or not this request requires authentication. If YES, the credentials will be added to the request headers before sending the request. If NO, they will not.

@property (nonatomic, assign) BOOL requiresAuthentication

Declared In

SFRestRequest.h

  timeoutInterval

Assigns the timeout interval allowed for this request.

@property (nonatomic, assign, readwrite) NSTimeInterval timeoutInterval

Declared In

SFRestRequest.h

– prepareRequestForSend:

Prepares the request before sending it out.

- (nullable NSURLRequest *)prepareRequestForSend:(nonnull SFUserAccount *)user

Parameters

user

User account.

Return Value

NSURLRequest instance.

Declared In

SFRestRequest.h

– setHeaderValue:forHeaderName:

Sets the value for the specified HTTP header.

- (void)setHeaderValue:(nullable NSString *)value forHeaderName:(NSString *)name

Parameters

value

The header value. If value is nil, this method will remove the HTTP header from the collection of headers.

name

The name of the HTTP header to set.

Declared In

SFRestRequest.h

– cancel

Cancels this request if it is running.

- (void)cancel

Declared In

SFRestRequest.h

– addPostFileData:paramName:fileName:mimeType:params:

Add file to upload

- (void)addPostFileData:(NSData *)fileData paramName:(NSString *)paramName fileName:(NSString *)fileName mimeType:(NSString *)mimeType params:(nullable NSDictionary *)params

Parameters

fileData

Value of this POST parameter

paramName

Name of the POST parameter

fileName

Name of the file

mimeType

MIME type of the file

params

File properties (e.g. title, desc, contentSize)

Declared In

SFRestRequest.h

– setCustomRequestBodyString:contentType:

Sets a custom request body based on an NSString representation.

- (void)setCustomRequestBodyString:(NSString *)bodyString contentType:(NSString *)contentType

Parameters

bodyString

The NSString object representing the request body.

contentType

The content type associated with this request.

Declared In

SFRestRequest.h

– setCustomRequestBodyDictionary:contentType:

Sets a custom request body based on an NSDictionary representation.

- (void)setCustomRequestBodyDictionary:(NSDictionary *)bodyDictionary contentType:(NSString *)contentType

Parameters

bodyDictionary

The NSDictionary object representing the request body.

contentType

The content type associated with this request.

Declared In

SFRestRequest.h

– setCustomRequestBodyData:contentType:

Sets a custom request body based on an NSData representation.

- (void)setCustomRequestBodyData:(NSData *)bodyData contentType:(NSString *)contentType

Parameters

bodyData

The NSData object representing the request body.

contentType

The content type associated with this request.

Declared In

SFRestRequest.h

– setCustomRequestBodyStream:contentType:

Sets a custom request body based on an NSInputStream representation.

- (void)setCustomRequestBodyStream:(NSInputStream *( ^ ) ( void ))bodyStreamBlock contentType:(NSString *)contentType

Parameters

bodyStreamBlock

The block that will return an NSInputStream object representing the request body.

contentType

The content type associated with this request.

Declared In

SFRestRequest.h

+ isNetworkError:

Indicates whether the error code of the given error specifies a network error.

+ (BOOL)isNetworkError:(NSError *)error

Parameters

error

The error object to check

Return Value

YES if the error code of the given error specifies a network error

Declared In

SFRestRequest.h

+ httpMethodFromSFRestMethod:

Return HTTP method as string for SFRestMethod

+ (NSString *)httpMethodFromSFRestMethod:(SFRestMethod)restMethod

Parameters

restMethod

The SFRestMethod

Return Value

the HTTP string for the given SFRestMethod

Declared In

SFRestRequest.h

+ sfRestMethodFromHTTPMethod:

+ (SFRestMethod)sfRestMethodFromHTTPMethod:(NSString *)httpMethod

Parameters

httpMethod

An HTTP method; for example, “get” or “post”

Return Value

The SFRestMethod enumerator for the given HTTP method

Declared In

SFRestRequest.h

+ requestWithMethod:path:queryParams:

Creates an SFRestRequest object. See SFRestMethod. If you need to set body on the request, use one of the ‘setCustomRequestBody…’ methods to do so with the instance returned by this method.

+ (instancetype)requestWithMethod:(SFRestMethod)method path:(NSString *)path queryParams:(nullable NSDictionary<NSString*,id> *)queryParams

Parameters

method

the HTTP method

path

the request path

queryParams

the parameters of the request (could be nil)

Declared In

SFRestRequest.h

+ requestWithMethod:serviceHostType:path:queryParams:

Creates an SFRestRequest object. See SFRestMethod. If you need to set body on the request, use one of the ‘setCustomRequestBody…’ methods to do so with the instance returned by this method.

+ (instancetype)requestWithMethod:(SFRestMethod)method serviceHostType:(SFSDKRestServiceHostType)hostType path:(NSString *)path queryParams:(nullable NSDictionary<NSString*,id> *)queryParams

Parameters

method

the HTTP method

hostType

the type of service host for the request.

path

the request path

queryParams

the parameters of the request (could be nil)

Declared In

SFRestRequest.h

+ requestWithMethod:baseURL:path:queryParams:

Creates an SFRestRequest object. To set the body of the request, use one of the setCustomRequestBody... methods on the returned instance.

+ (instancetype)requestWithMethod:(SFRestMethod)method baseURL:(NSString *)baseURL path:(NSString *)path queryParams:(nullable NSDictionary<NSString*,id> *)queryParams

Parameters

method

HTTP method

baseURL

Request URL

path

Request path

queryParams

Parameters of the request (can be nil)

See Also

Declared In

SFRestRequest.h

+ customUrlRequestWithMethod:baseURL:path:queryParams:

Creates an SFRestRequest object to be used with non-Salesforce endpoints. To set body on the request, use one of the ‘setCustomRequestBody…’ methods on the returned instance.

+ (instancetype)customUrlRequestWithMethod:(SFRestMethod)method baseURL:(NSString *)baseURL path:(NSString *)path queryParams:(nullable NSDictionary<NSString*,id> *)queryParams

Parameters

method

the HTTP method

baseURL

the request URL

path

the request path

queryParams

the parameters of the request (could be nil)

See Also

Declared In

SFRestRequest.h

+ customEndPointRequestWithMethod:endPoint:path:queryParams:

Creates an SFRestRequest object to be used with custom Salesforce endpoints. See SFRestMethod. If you need to set body on the request, use one of the ‘setCustomRequestBody…’ methods to do so with the instance returned by this method.

+ (instancetype)customEndPointRequestWithMethod:(SFRestMethod)method endPoint:(NSString *)endPoint path:(NSString *)path queryParams:(nullable NSDictionary<NSString*,id> *)queryParams

Parameters

method

the HTTP method

path

the request path

queryParams

the parameters of the request (could be nil)

Declared In

SFRestRequest.h

Extension Methods

  request

@property (nonnull, nonatomic, strong, readwrite) NSMutableURLRequest *request

  requestBodyStreamBlock

@property (nullable, nonatomic, copy) NSInputStream *( ^ ) ( void ) requestBodyStreamBlock

  requestBodyAsDictionary

@property (nullable, nonatomic, copy) NSDictionary *requestBodyAsDictionary

  requestContentType

@property (nullable, nonatomic, copy) NSString *requestContentType

  instrumentationDelegateInternal

@property (nullable, nonatomic, strong) id<SFRestRequestDelegate> instrumentationDelegateInternal

+ restUrlForBaseUrl:serviceHostType:credentials:

+ (nonnull NSString *)restUrlForBaseUrl:(nullable NSString *)baseUrl serviceHostType:(SFSDKRestServiceHostType)hostType credentials:(nonnull SFOAuthCredentials *)credentials

+ toQueryString:

+ (NSString *)toQueryString:(nullable NSDictionary *)components