Index

RBRestClient.swift

Protocols

Classes


RBRestClient

Provides a easy to use FLUENT based networking client for most networking scenarios.

Properties

Whether or not request URL's should be printed for all requests.
public var printRequestURL Bool { get set }

Whether or not request bodies should be printed for all requests.
public var printRequestBody Bool { get set }

Whether or not request headers should be printed for all requests.
public var printRequestHeaders Bool { get set }

Whether or not validation failures should be printed for all requests.
public var printValidationFailure Bool { get set }

Whether or not response URL's should be printed for all responses.
public var printResponseURL Bool { get set }

Whether or not response bodies should be printed for all responses.
public var printResponseBody Bool { get set }

Whether or not response headers should be printed for all responses.
public var printResponseHeaders Bool { get set }

Headers that should be added to all requests originating from this client.
public var applyAdditionalHeaders [String : String]? { get set }

Query string parameters that should be added to all requests originating from this client.
public var applyAdditionalParameters [String : String]? { get set }

The base URL to use if none is specified.
public var baseURL URL { get }

The RBNetworkClient that underpins this client.
public var networkClient RBNetworkClient { get }

Delegate.
public weak var delegate RBRestClientDelegate? { get set }

Functions

Create a request with a specific URLRequest.
@param request : The request. Allows requests to be made to URL's other than those relating to the baseURL.
@returns A FLUENT request object.
public func request(request: URLRequest) -> RBRestClientRequest

Create a request with a specific url.
@param url : The url. Allows requests to be made to URL's other than those relating to the baseURL.
@param method : HTTP method type e.g. POST/GET/DELETE...
@returns A FLUENT request object.
public func request(_ url: URL, _ method: RBNetworkRequestMethod) -> RBRestClientRequest

Create a request with a specific URLRequest.
@param method : HTTP method type e.g. POST/GET/DELETE...
@returns A FLUENT request object.
public func request(_ method: RBNetworkRequestMethod) -> RBRestClientRequest


RBRestClientRequest

Provides a easy to use FLUENT based networking request.

Properties

Whether or not the request URL should be printed for this request.
public var printRequestURL Bool { get set }

Whether or not the request body should be printed for this request.
public var printRequestBody Bool { get set }

Whether or not the request headers should be printed for this request.
public var printRequestHeaders Bool { get set }

Whether or not the validation failures should be printed for this request.
public var printValidationFailure Bool { get set }

Whether or not the response URL should be printed for this request.
public var printResponseURL Bool { get set }

Whether or not the response body should be printed for this request.
public var printResponseBody Bool { get set }

Whether or not the response headers should be printed for this request.
public var printResponseHeaders Bool { get set }

Functions

Add a path to the current URL e.g. URL = http://www.redbeard.io/, path = /categories/1
@param path : The path to add.
@returns The updated RBRestClientRequest object.
public func addPath(_ path: String) -> RBRestClientRequest

Set the content type header using RBMimeType.
@param type : The content type.
@returns The updated RBRestClientRequest object.
public func contentType(_ type: RBMimeType) -> RBRestClientRequest

Set the accept header using RBMimeType.
@param type : The content type.
@returns The updated RBRestClientRequest object.
public func accept(_ type: RBMimeType) -> RBRestClientRequest

Adds a new header value.
@param value : The header value.
@param name : The header name.
@returns The request builder so that you can continue to call methods.
public func addHeader(_ value: String, _ name: String) -> RBRestClientRequest

Sets the headers.
@param params : The headers.
@returns The request builder so that you can continue to call methods.
public func headers(_ params: [String : String]) -> RBRestClientRequest

Adds a new query parameter.
@param value : The query value.
@param name : The query name.
@returns The request builder so that you can continue to call methods.
public func addParameter(_ value: String, _ name: String) -> RBRestClientRequest

Sets query parameters.
@param params : The parameters
@returns The request builder so that you can continue to call methods.
public func parameters(_ params: [String : String]) -> RBRestClientRequest

Sets body data.
@param data : The data.
@returns The request builder so that you can continue to call methods.
public func body(data: Data) -> RBRestClientRequest

Sets body data.
@param json : The json object.
@returns The request builder so that you can continue to call methods.
public func body(_ json: RBJsonObject) -> RBRestClientRequest

Sets body data.
@param json : The json dictionary.
@returns The request builder so that you can continue to call methods.
public func body(_ json: [String : Any?]) -> RBRestClientRequest

Set a validation to check for a specific HTTP status code.
@param statusCode : The specific status code to check for.
@returns The updated RBRestClientRequest object.
public func validateStatusCode(_ statusCode: Int) -> RBRestClientRequest

Set a validation to check for a HTTP status code range.
@param range : The status code range to check for.
@returns The updated RBRestClientRequest object.
public func validateStatusCode(_ range: ClosedRange<Int>) -> RBRestClientRequest

Set a validation to check for a specific HTTP content type.
@param contentType : The specific content type to check for.
@returns The updated RBRestClientRequest object.
public func validateContentType(_ contentType: String) -> RBRestClientRequest

Set a validation to check a response body is present
@returns The updated RBRestClientRequest object.
public func validateBodyPresent() -> RBRestClientRequest

Set all request debug printing options in a single method call.
@param printRequestURL : Whether or not the request URL should be printed for this request.
@param printRequestHeaders : Whether or not the request body should be printed for this request.
@param printRequestBody : Whether or not the request headers should be printed for this request.
@returns The updated RBRestClientRequest object.
public func printRequest(_ printRequestURL: Bool, _ printRequestHeaders: Bool, _ printRequestBody: Bool) -> RBRestClientRequest

Set all response debug printing options in a single method call.
@param printValidationFailure : Whether or not the validation failures should be printed for this request.
@param printResponseURL : Whether or not the response URL should be printed for this request.
@param printResponseHeaders : Whether or not the response body should be printed for this request.
@param printResponseBody : Whether or not the response headers should be printed for this request.
@returns The updated RBRestClientRequest object.
public func printResponse(_ printValidationFailure: Bool, _ printResponseURL: Bool, _ printResponseHeaders: Bool, _ printResponseBody: Bool) -> RBRestClientRequest

Receive progress updates for a request.
@param queue : Optional dispath queue on which to receive updates. If nil then DispathQueue.main will be used.
@param onProgress : Block that should receive updates.
@returns The updated RBRestClientRequest object.
public func onProgress(_ queue: DispatchQueue? = nil, _ onProgress: @escaping RBRestClientProgressBlock) -> RBRestClientRequest

Initiates a raw response for the request.
@param queue : Optional dispath queue on which to receive updates. If nil then DispathQueue.main will be used.
@param completion : Completion block.
public func response(_ queue: DispatchQueue? = nil, completion: ((_ isValid: Bool, _ response: RBRestClientResponse) -> Void)?)

Initiates a typed RBJsonObject response for the request.
@param queue : Optional dispath queue on which to receive updates. If nil then DispathQueue.main will be used.
@param jsonPath : Optional json path to first follow before deserialisation of the json to the specified type occurs e.g. data.results[0].
@param completion : Completion block.
public func responseJSON<T : RBJsonObject>(_ queue: DispatchQueue? = nil, type: T.Type, jsonPath: String?, completion: ((_ isValid: Bool, _ json: T?, _ response: RBRestClientResponse) -> Void)?)

Initiates a typed RBJsonObject array response for the request.
@param queue : Optional dispath queue on which to receive updates. If nil then DispathQueue.main will be used.
@param jsonPath : Optional json path to first follow before deserialisation of the json to the specified type occurs e.g. data.results[0].
@param completion : Completion block.
@returns The updated RBRestClientRequest object.
public func responseJSON<T : RBJsonObject>(_ queue: DispatchQueue? = nil, arrayType: T.Type, jsonPath: String?, completion: ((_ isValid: Bool, _ json: [T]?, _ response: RBRestClientResponse) -> Void)?)


RBRestClientResponse

Captures a HTTP Response.

Properties

Whether or not the result is valid. This will be false if a network or validation failure occured.
public var isValid Bool { get }

Specific detail on the error if one has occured.
public var error Error? { get }

The underlying network opertation that contains the response.
public var operation RBNetworkOperation? { get }

The HTTP status code if available otherwise 0.
public var httpStatusCode Int { get }

The underlying HTTP response object.
public var httpURLResponse HTTPURLResponse? { get }

The response data.
public var data Data? { get }

Functions

Deserializes the data property to a JSON object.
@returns The JSON as dictionary or an array of dictionaries as appropriate or nil if data is empty or the response was invalid.
public func dataAsJson() -> Any?

Deserializes the data property to a typed RBJsonObject object.
@returns The JSON as a specific RBJsonObject instance or nil if data is empty or the response was invalid.
public func dataToJson<T: RBJsonObject>() -> [T]?

Deserializes the data property to a typed array of RBJsonObject objects.
@returns The JSON as an array of specific RBJsonObject instances or nil if data is empty or the response was invalid.
public func dataToJson<T: RBJsonObject>() -> T?

Deserializes the data property to a typed array of RBJsonObject objects.
@param encoding : Optional string encoding to use. Default = UTF8.
@returns The data as a decoded string or nil if data is empty or the response was invalid.
public func dataToString(encoding: String.Encoding = String.Encoding.utf8) -> String?