APIRequestType

public protocol APIRequestType : AnyObject, CustomStringConvertible, SchedulableTask

A protocol that needs to be conformed to by custom server API requests.

  • id

    A unique ID for the request.

    Declaration

    Swift

    var id: UUID { get }
  • request Default implementation

    The Alamofire.Request object. Default implementation exists.

    Default Implementation

    The Alamofire.Request object for this APIRequest object. This default implementation should suffice.

    Declaration

    Swift

    var request: Alamofire.Request? { get }
  • response Default implementation

    HTTP Response. Default implementation exists.

    Default Implementation

    The HTTPURLResponse generated by this request. Only available after the request has finished.

    Declaration

    Swift

    var response: HTTPURLResponse? { get }
  • The executing behavior.

    Declaration

    Swift

    var executionBehavior: APIRequestExecutionBehavior { get set }
  • The configuration of type APIRequestConfigurationType.

    Declaration

    Swift

    var config: APIRequestConfigurationType { get }
  • The status of the API request execution. See APIRequestStatus for values.

    Declaration

    Swift

    var status: APIRequestStatus { get set }
  • An error resulted from the API call execution.

    Declaration

    Swift

    var error: UsherErrorProtocol? { get set }
  • An Alamofire Timeline object for obtaining the timing metrics for the complete lifecycle of the request.

    Declaration

    Swift

    var timeline: Timeline? { get set }
  • completionQueue Default implementation

    A queue to turn the completion of the request on. Default is DispatchQueue.main. Default implementation exists.

    Default Implementation

    The default completion queue used by the APIRequestType. Conform to the protocol with a completionQueue variable to provide a custom queue.

    Declaration

    Swift

    var completionQueue: DispatchQueue { get set }
  • Override to provide a custom session manager if necessary. Default implementation exists.

    Declaration

    Swift

    var sessionManager: Alamofire.SessionManager { get }
  • responseValidator Default implementation

    Custom response validation closure. Default implementation exists.

    Default Implementation
    Declaration

    Swift

    var responseValidator: Alamofire.DataRequest.Validation? { get }
  • Type alias for request completion closure returning a data object.

    Declaration

    Swift

    typealias APIRequestDataCompletion = (_ json: Data?, _ response: URLResponse?, _ error: UsherErrorProtocol?) -> ()
  • Type alias for request completion closure returning a decodable object.

    Declaration

    Swift

    typealias APIRequestDecodableCompletion<T> = (_ decodable: T?, _ error: UsherErrorProtocol?) -> ()
  • Container to store the closures.

    Declaration

    Swift

    var dataCompletions: [APIRequestDataCompletion] { get set }
  • responseData(_:) Default implementation

    Get notified for request completion with the raw Data response object. Default implementation exists.

    Default Implementation

    Default implementation of the protocol method. For most cases the default implementation should be enough. Provide your own if you desire more control.

    See also

    APIRequestDataCompletion
    Declaration

    Swift

    func responseData(_ completion: @escaping APIRequestDataCompletion)
  • Get notified for request completion with a specified decodable object. Default implementation exists.

    Default Implementation

    Default implementation of the protocol method. Will attempt to construct a Decodable object from json response. The path parameter can be used to construct the object using sub-json under a specific key.

    See also

    APIRequestDecodableCompletion
    Declaration

    Swift

    func responseDecodable<T: Decodable>(forPath path: String?, completion: @escaping APIRequestDecodableCompletion<T>)
  • start() Extension method

    Start the request. The request will then be scheduled by APIRequestExecutor and executed accordingly. If overriding, in implementation make sure to call this default implementation using (self as APIRequestType).start()

    Declaration

    Swift

    public func start()
  • cancel() Extension method

    Cancel and stop the request. If overriding, in implementation make sure to call this default implementation using (self as APIRequestType).cancel().

    Declaration

    Swift

    public func cancel()
  • resetSession() Extension method

    Discard the current urlsession and configuration and create a new one.

    Declaration

    Swift

    public static func resetSession()
  • Register a URLCredentialProvider class for the specified NSURLAuthentication method. This class will be called in when using the URLCredentialProvider protocol APIs when the URLSession or URLSession task receives an authentication challenge. Not all NSURLAuthentication methods are supported. Please see URLAuthenticationMethod for supported types.

    APIRequestType provides a default URLCredentialProvider conforming class name ServerTrustManager for authentication URLAuthenticationMethod.serverTrust. It is used for certificate pinning. You can use ServerTrustManager to plug in your pinned certificates without having to rewrite a credential provider from scratch.

    Declaration

    Swift

    public static func registerCredentialProvider(_ provider: URLCredentialProvider.Type,
                                                  forMethod method: URLAuthenticationMethod)
    Parameters
    provider

    A class conforming to the URLCredentialProvider protocol.

    method

    The NSURLAuthenticationMethod for which the provider is being registered.

  • Get the registered credential provider class for the specified URLAuthenticationMethod.

    Declaration

    Swift

    public static func credentialProvider(forMethod method: URLAuthenticationMethod) -> URLCredentialProvider.Type?
  • description Extension method

    Description of the APIRequest.

    Declaration

    Swift

    public var description: String { get }
  • shortDescription Extension method

    Short string representation of the APIRequest.

    Declaration

    Swift

    public var shortDescription: String { get }