WLResourceRequest Class Reference
Inherits from | NSObject |
Declared in | WLResourceRequest.h |
Overview
This class encapsulates a resource request. The resource may be an adapter on the MobileFirst server, or an external resource. The class provides several ‘send’ methods, with different inputs for the body of a request.
Tasks
-
url
property -
scope
property -
httpMethod
property -
queryParameters
property -
headers
property -
timeoutInterval
property -
stringEncoding
property -
+ requestWithURL:method:
-
+ requestWithURL:method:backendServiceName:timeout:
-
+ requestWithURL:method:scope:
-
+ requestWithURL:method:timeout:
-
+ requestWithURL:method:timeout:scope:
-
– setQueryParameterValue:forName:
-
– getQueryString
-
– headerNames
-
– headersForName:
-
– headerForName:
-
– setHeaderValue:forName:
-
– addHeaderValue:forName:
-
– removeHeadersForName:
-
– sendWithCompletionHandler:
-
– sendWithCompletionHandler:completionHandler:
-
– sendWithDelegate:
-
– sendWithDelegate:responseQueue:
-
– sendWithBody:completionHandler:
-
– sendWithBody:responseQueue:completionHandler:
-
– sendWithBody:delegate:
-
– sendWithBody:delegate:responseQueue:
-
– sendWithFormParameters:completionHandler:
-
– sendWithFormParameters:responseQueue:completionHandler:
-
– sendWithFormParameters:delegate:
-
– sendWithFormParameters:delegate:responseQueue:
-
– sendWithJSON:completionHandler:
-
– sendWithJSON:responseQueue:completionHandler:
-
– sendWithJSON:delegate:
-
– sendWithJSON:delegate:responseQueue:
-
– sendWithData:completionHandler:
-
– sendWithData:responseQueue:completionHandler:
-
– sendWithData:delegate:
-
– sendWithData:delegate:responseQueue:
Properties
headers
Array of request headers
@property (nonatomic) NSArray *headers
Declared In
WLResourceRequest.h
httpMethod
HTTP method of the request
@property (readonly) NSString *httpMethod
Declared In
WLResourceRequest.h
queryParameters
Dictionary of query parameters
@property (nonatomic) NSDictionary *queryParameters
Declared In
WLResourceRequest.h
scope
Scope protecting the request
@property (readonly) NSString *scope
Declared In
WLResourceRequest.h
stringEncoding
Request string encoding
@property (nonatomic, assign) NSStringEncoding stringEncoding
Declared In
WLResourceRequest.h
Class Methods
requestWithURL:method:
Creates an instance of WLresourceRequest
with the specified URL and method
+ (WLResourceRequest *)requestWithURL:(NSURL *)url method:(NSString *)method
Parameters
- url
URL of the request (full or relative to MobileFirst Server)
- method
Method of the request (POST, GET,…)
Declared In
WLResourceRequest.h
requestWithURL:method:backendServiceName:timeout:
Constructs a new resource request with the specified URL, using the specified HTTP method. Additionally this constructor sets a custom expiration period (timeout) for the request.
The WLResourceRequest API can be used to allow mobile apps access to microservices hosted outside of Mobile Foundatione. Mobile Foundation facilitates secure calls to microservice or enterprise backend service without involving adapters though Mobile Foundation API Connector.
To access a microservice URL
such as "[http://mybluemix.net/resorts/cities](http://mybluemix.net/resorts/cities)" and the Mobile Foundation runtime backend service is configured as follows
{ “service”: “resorts”, “baseUrl”:“http://mybluemix.net/resorts” }
+ (WLResourceRequest *)requestWithURL:(NSURL *)url method:(NSString *)method backendServiceName:(NSString *)backendServiceName timeout:(NSTimeInterval)timeoutInterval
Parameters
- url
Relative URL of the microservice endpoint. For example :
cities
- method
HTTP method to use.
- backendServiceName
Name of the backend service configured on server to fetch data from. For example :
resorts
- timeout
The timeout in milliseconds for this request. For example :
3000
@example WLResourceRequest* request = [WLResourceRequest requestWithURL:@“cities” method:WLHttpMethodGet backendServiceName:@“resorts” timeout:3000];
Declared In
WLResourceRequest.h
requestWithURL:method:scope:
Creates an instance of WLresourceRequest
with the specified URL and method
+ (WLResourceRequest *)requestWithURL:(NSURL *)url method:(NSString *)method scope:(NSString *)scope
Parameters
- url
URL of the request (full or relative to MobileFirst Server)
- method
Method of the request (POST, GET,…)
- scope
the scope that this protected resource requires
Declared In
WLResourceRequest.h
requestWithURL:method:timeout:
Creates an instance of WLresourceRequest
with the specified URL, method, and timeout
+ (WLResourceRequest *)requestWithURL:(NSURL *)url method:(NSString *)method timeout:(NSTimeInterval)timeout
Parameters
- url
URL of the request (full or relative to MobileFirst Server)
- method
Method of the request (POST, GET,…)
- timeout
Timeout of the request in seconds
Declared In
WLResourceRequest.h
requestWithURL:method:timeout:scope:
Creates an instance of WLresourceRequest
with the specified URL, method, and timeout
+ (WLResourceRequest *)requestWithURL:(NSURL *)url method:(NSString *)method timeout:(NSTimeInterval)timeout scope:(NSString *)scope
Parameters
- url
URL of the request (full or relative to MobileFirst Server)
- method
Method of the request (POST, GET,…)
- timeout
Timeout of the request in seconds
- scope
the scope that this protected resource requires
Declared In
WLResourceRequest.h
Instance Methods
addHeaderValue:forName:
Adds the header to the request
- (void)addHeaderValue:(NSObject *)value forName:(NSString *)name
Parameters
- value
Header value
- name
Header name
Discussion
If a header with the same name already exists, the values are concatenated and separated by commas.
Note: The header name is case insensitive.
Declared In
WLResourceRequest.h
getQueryString
Returns the query parameters as string
- (NSString *)getQueryString
Declared In
WLResourceRequest.h
headerForName:
Returns first header with matching name
- (NSString *)headerForName:(NSString *)name
Parameters
- name
name of the header
Declared In
WLResourceRequest.h
headerNames
Returns header names as an array of strings
- (NSArray *)headerNames
Declared In
WLResourceRequest.h
headersForName:
Returns header name as an array of strings
- (NSArray *)headersForName:(NSString *)name
Parameters
- name
Header name
Discussion
For a single header name, there can be several values separated by commas. If there is only one value, the method returns an array with one element.
Declared In
WLResourceRequest.h
removeHeadersForName:
Removes the header from the request
- (void)removeHeadersForName:(NSString *)name
Parameters
- name
Header name
Declared In
WLResourceRequest.h
sendWithBody:completionHandler:
Sends a request with the provided text as a request body and uses a completionHandler
block to handle the response
- (void)sendWithBody:(NSString *)body completionHandler:(void ( ^ ) ( WLResponse *response , NSError *error ))completionHandler
Parameters
- body
Request body
- completionHandler
(void(^) (WLResponse response, NSError error)) Block that is triggered when a response has been received Note: Using methods other than POST or PUT will omit the request body.
Declared In
WLResourceRequest.h
sendWithBody:delegate:
Sends a request with the provided text as a request body and uses a delegate to handle the response
- (void)sendWithBody:(NSString *)body delegate:(id)delegate
Parameters
- body
Request body
- delegate
Delegate that conforms to both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols Note: The delegate must implement bothNSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols. Note: Using methods other than POST or PUT will omit the request body.
Declared In
WLResourceRequest.h
sendWithBody:delegate:responseQueue:
Sends a request with the provided text as a request body and uses a delegate to handle the response
- (void)sendWithBody:(NSString *)body delegate:(id)delegate responseQueue:(dispatch_queue_t)queue
Parameters
- body
Request body
- delegate
Delegate that conforms to both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols
- queue
private queue to specify callback queue for delegate Note: The delegate must implement both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols. Note: Using methods other than POST or PUT will omit the request body.
Declared In
WLResourceRequest.h
sendWithBody:responseQueue:completionHandler:
Sends a request with the provided text as a request body and uses a completionHandler
block to handle the response
- (void)sendWithBody:(NSString *)body responseQueue:(dispatch_queue_t)queue completionHandler:(void ( ^ ) ( WLResponse *response , NSError *error ))completionHandler
Parameters
- body
Request body
- queue
private queue to specify callback queue for completionHandler block
- completionHandler
(void(^) (WLResponse response, NSError error)) Block that is triggered when a response has been received Note: Using methods other than POST or PUT will omit the request body.
Declared In
WLResourceRequest.h
sendWithCompletionHandler:
Sends a request and uses the completionHandler
block to handle the response
- (void)sendWithCompletionHandler:(void ( ^ ) ( WLResponse *response , NSError *error ))completionHandler
Parameters
- completionHandler
(void(^) (WLResponse response, NSError error)) Block that is triggered when a response has been received.
Declared In
WLResourceRequest.h
sendWithCompletionHandler:completionHandler:
Sends a request and uses the completionHandler
block to handle the response
- (void)sendWithCompletionHandler:(dispatch_queue_t)queue completionHandler:(void ( ^ ) ( WLResponse *response , NSError *error ))completionHandler
Parameters
- queue
private queue to specify callback queue for completionHandler block
- completionHandler
(void(^) (WLResponse response, NSError error)) Block that is triggered when a response has been received.
Declared In
WLResourceRequest.h
sendWithData:completionHandler:
Sends a request with the provided request data and uses completionHandler
block to handle the response
- (void)sendWithData:(NSData *)data completionHandler:(void ( ^ ) ( WLResponse *response , NSError *error ))completionHandler
Parameters
- data
Request data
- completionHandler
(void(^) (WLResponse response, NSError error)) Block that is triggered when a response has been received Note: Using methods other than POST or PUT will omit the request body.
Declared In
WLResourceRequest.h
sendWithData:delegate:
Sends a request with the provided request data and uses a delegate to handle the response
- (void)sendWithData:(NSData *)data delegate:(id)delegate
Parameters
- data
Request data
- delegate
Delegate that conforms to both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols Note: The delegate must implement bothNSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols. Note: Using methods other than POST or PUT will omit the request body
Declared In
WLResourceRequest.h
sendWithData:delegate:responseQueue:
Sends a request with the provided request data and uses a delegate to handle the response
- (void)sendWithData:(NSData *)data delegate:(id)delegate responseQueue:(dispatch_queue_t)queue
Parameters
- data
Request data
- delegate
Delegate that conforms to both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols
- queue
private queue to specify callback queue for delegate Note: The delegate must implement both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols. Note: Using methods other than POST or PUT will omit the request body
Declared In
WLResourceRequest.h
sendWithData:responseQueue:completionHandler:
Sends a request with the provided request data and uses completionHandler
block to handle the response
- (void)sendWithData:(NSData *)data responseQueue:(dispatch_queue_t)queue completionHandler:(void ( ^ ) ( WLResponse *response , NSError *error ))completionHandler
Parameters
- data
Request data
- queue
private queue to specify callback queue for completionHandler block
- completionHandler
(void(^) (WLResponse response, NSError error)) Block that is triggered when a response has been received Note: Using methods other than POST or PUT will omit the request body.
Declared In
WLResourceRequest.h
sendWithDelegate:
Sends a request and uses a delegate to handle the response
- (void)sendWithDelegate:(id)delegate
Parameters
- delegate
Delegate that conforms to both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols Note: The delegate must implement bothNSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols.
Declared In
WLResourceRequest.h
sendWithDelegate:responseQueue:
Sends a request and uses a delegate to handle the response
- (void)sendWithDelegate:(id)delegate responseQueue:(dispatch_queue_t)queue
Parameters
- delegate
Delegate that conforms to both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols
- queue
private queue to specify callback queue for delegate Note: The delegate must implement both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols.
Declared In
WLResourceRequest.h
sendWithFormParameters:completionHandler:
Sends a request with form parameters as a request body and uses a completionHandler
block to handle the response
- (void)sendWithFormParameters:(NSDictionary *)formParameters completionHandler:(void ( ^ ) ( WLResponse *response , NSError *error ))completionHandler
Parameters
- completionHandler
(void(^) (WLResponse response, NSError error)) Block that is triggered when a response has been received Note: Using methods other than POST or PUT will omit the request body.
- bodyParameters
Dictionary of form parameters
Declared In
WLResourceRequest.h
sendWithFormParameters:delegate:
Sends a request with form parameters as a request body and uses a delegate to handle the response
- (void)sendWithFormParameters:(NSDictionary *)formParameters delegate:(id)delegate
Parameters
- delegate
Delegate that conforms to both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols Note: The delegate must implement bothNSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols. Note: Using methods other than POST or PUT will omit the request body.
- bodyParameters
Dictionary of form parameters
Declared In
WLResourceRequest.h
sendWithFormParameters:delegate:responseQueue:
Sends a request with form parameters as a request body and uses a delegate to handle the response
- (void)sendWithFormParameters:(NSDictionary *)formParameters delegate:(id)delegate responseQueue:(dispatch_queue_t)queue
Parameters
- delegate
Delegate that conforms to both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols
- queue
private queue to specify callback queue for delegate Note: The delegate must implement both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols. Note: Using methods other than POST or PUT will omit the request body.
- bodyParameters
Dictionary of form parameters
Declared In
WLResourceRequest.h
sendWithFormParameters:responseQueue:completionHandler:
Sends a request with form parameters as a request body and uses a completionHandler
block to handle the response
- (void)sendWithFormParameters:(NSDictionary *)formParameters responseQueue:(dispatch_queue_t)queue completionHandler:(void ( ^ ) ( WLResponse *response , NSError *error ))completionHandler
Parameters
- queue
private queue to specify callback queue for completionHandler block
- completionHandler
(void(^) (WLResponse response, NSError error)) Block that is triggered when a response has been received Note: Using methods other than POST or PUT will omit the request body.
- bodyParameters
Dictionary of form parameters
Declared In
WLResourceRequest.h
sendWithJSON:completionHandler:
Sends a request with the provided JSON and uses a completionHandler
block to handle the response
- (void)sendWithJSON:(NSDictionary *)json completionHandler:(void ( ^ ) ( WLResponse *response , NSError *error ))completionHandler
Parameters
- json
JSON as a dictionary
- completionHandler
(void(^) (WLResponse response, NSError error)) Block that is triggered when a response has been received Note: Using methods other than POST or PUT will omit the request body.
Declared In
WLResourceRequest.h
sendWithJSON:delegate:
Sends a request with the provided JSON and uses a delegate to handle the response
- (void)sendWithJSON:(NSDictionary *)json delegate:(id)delegate
Parameters
- json
JSON as a dictionary
- delegate
Delegate that conforms to both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols Note: The delegate must implement bothNSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols. Note: Using methods other than POST or PUT will omit the request body.
Declared In
WLResourceRequest.h
sendWithJSON:delegate:responseQueue:
Sends a request with the provided JSON and uses a delegate to handle the response
- (void)sendWithJSON:(NSDictionary *)json delegate:(id)delegate responseQueue:(dispatch_queue_t)queue
Parameters
- json
JSON as a dictionary
- delegate
Delegate that conforms to both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols
- queue
private queue to specify callback queue for delegate Note: The delegate must implement both
NSURLSessionDataDelegate
andNSURLSessionTaskDelegate
protocols. Note: Using methods other than POST or PUT will omit the request body.
Declared In
WLResourceRequest.h
sendWithJSON:responseQueue:completionHandler:
Sends a request with the provided JSON and uses a completionHandler
block to handle the response
- (void)sendWithJSON:(NSDictionary *)json responseQueue:(dispatch_queue_t)queue completionHandler:(void ( ^ ) ( WLResponse *response , NSError *error ))completionHandler
Parameters
- json
JSON as a dictionary
- queue
private queue to specify callback queue for completionHandler block
- completionHandler
(void(^) (WLResponse response, NSError error)) Block that is triggered when a response has been received Note: Using methods other than POST or PUT will omit the request body.
Declared In
WLResourceRequest.h
setHeaderValue:forName:
Sets the header for the request
- (void)setHeaderValue:(NSObject *)value forName:(NSString *)name
Parameters
- value
Header value
- name
Header name
Discussion
If a header with the same name already exists, it is overridden.
Note: The header name is case insensitive.
Declared In
WLResourceRequest.h
setQueryParameterValue:forName:
Sets query parameter value
- (void)setQueryParameterValue:(NSString *)parameterValue forName:(NSString *)parameterName
Parameters
- parameterValue
Parameter value
- parameterName
Parameter name
Discussion
If the query parameter with the same name already exists, it is overridden.
Declared In
WLResourceRequest.h