Request

public final class Request : Operation
extension Request: NSCopying

The core class of TermiNetwork. It handles the request creation and its execution.

Public properties

  • The configuration of the request. This will be merged with the environment configuration if needed.

    Declaration

    Swift

    public var configuration: Configuration
  • The number of the retries initiated by interceptor.

    Declaration

    Swift

    public var retryCount: Int
  • The environment of the request.

    Declaration

    Swift

    public var environment: Environment?
  • An associated object with the request. Use this variable to optionaly assign an object to it, for later use.

    Declaration

    Swift

    public var associatedObject: AnyObject?
  • The headers of the request.

    Declaration

    Swift

    public var headers: [String : String]?
  • The parameters of the request.

    Declaration

    Swift

    public var params: [String : Any?]?

Initializers

  • Initializes a Request.

    Declaration

    Swift

    public init(method: Method,
                url: String,
                headers: [String: String]? = nil,
                params: [String: Any?]? = nil,
                configuration: Configuration? = nil)

    Parameters

    method

    A Method to use, for example: .get, .post, etc.

    url

    The URL of the request.

    headers

    A Dictionary of header values, etc. “Content-type”: “text/html”

    params

    The parameters of the request. (optional)

    configuration

    A configuration object (optional, e.g. if you want ot use custom configuration for the request).

  • Initializes a Request.

    Declaration

    Swift

    public convenience init(route: RouteProtocol,
                            environment: Environment? = Environment.current)

    Parameters

    route

    a RouteProtocol enum value

    environment

    Specifies a different environment to use than the global setted environment.

Public methods

  • Converts a Request instance an URLRequest instance.

    Declaration

    Swift

    public func asRequest() throws -> URLRequest
  • Cancels a request

    Declaration

    Swift

    public override func cancel()

Operation

  • Overrides the start() function from Operation class. You should never call this function directly. If you want to start a request without callbacks use startEmpty() instead.

    Declaration

    Swift

    public override func start()
  • Starts a request without callbacks.

    Declaration

    Swift

    public func startEmpty(_ queue: Queue? = nil) -> Request

    Parameters

    queue

    A Queue instance. If no queue is specified it uses the default one.

  • Adds a request to a queue and starts a download process for Decodable types.

    Declaration

    Swift

    @discardableResult
    public func start<T: Decodable>(queue: Queue? = Queue.shared,
                                    responseType: T.Type,
                                    onSuccess: SuccessCallback<T>?,
                                    onFailure: FailureCallback? = nil) -> Request

    Parameters

    queue

    A Queue instance. If no queue is specified it uses the default one.

    responseType

    The type of the model that will be deserialized and will be passed to the success block.

    onSuccess

    specifies a success callback of type SuccessCallback.

    onFailure

    specifies a failure callback of type FailureCallback.

    Return Value

    The Request object.

  • Adds a request to a queue and starts its execution for Transformer types.

    Declaration

    Swift

    @discardableResult
    public func start<FromType: Decodable, ToType>(queue: Queue? = Queue.shared,
                                                   transformer: Transformer<FromType, ToType>.Type,
                                                   onSuccess: SuccessCallback<ToType>?,
                                                   onFailure: FailureCallback? = nil) -> Request

    Parameters

    queue

    A Queue instance. If no queue is specified it uses the default one.

    transformer

    The transformer object that handles the transformation.

    onSuccess

    specifies a success callback of type SuccessCallback.

    onFailure

    specifies a failure callback of type FailureCallback.

    Return Value

    The Request object.

  • Adds a request to a queue and starts its execution for UIImage|NSImage responses.

    Declaration

    Swift

    @discardableResult
    public func start<T: ImageType>(queue: Queue? = Queue.shared,
                                    responseType: T.Type,
                                    onSuccess: SuccessCallback<T>?,
                                    onFailure: FailureCallback? = nil) -> Request

    Parameters

    queue

    A Queue instance. If no queue is specified it uses the default one.

    responseType

    The response type is UIImage.self or NSImage.self.

    onSuccess

    specifies a success callback of type SuccessCallback.

    onFailure

    specifies a failure callback of type FailureCallback.

    Return Value

    The Request object.

  • Adds a request to a queue and starts its execution for String responses.

    Declaration

    Swift

    @discardableResult
    public func start(queue: Queue? = Queue.shared,
                      responseType: String.Type,
                      onSuccess: SuccessCallback<String>?,
                      onFailure: FailureCallback? = nil) -> Request

    Parameters

    queue

    A Queue instance. If no queue is specified it uses the default one.

    responseType

    The response type is String.self.

    onSuccess

    specifies a success callback of type SuccessCallback

    onFailure

    specifies a failure callback of type FailureCallback

  • Adds a request to a queue and starts its execution for Data responses.

    Declaration

    Swift

    @discardableResult
    public func start(queue: Queue? = Queue.shared,
                      responseType: Data.Type,
                      onSuccess: SuccessCallback<Data>?,
                      onFailure: FailureCallback? = nil) -> Request

    Parameters

    queue

    A Queue instance. If no queue is specified it uses the default one.

    responseType

    The response type is Data.self.

    onSuccess

    specifies a success callback of type SuccessCallback

    onFailure

    specifies a failure callback of type FailureCallback

  • Adds a request to a queue and starts an upload process for Data types.

    Declaration

    Swift

    @discardableResult
    public func startUpload(queue: Queue? = Queue.shared,
                            responseType: Data.Type,
                            progressUpdate: ProgressCallbackType?,
                            onSuccess: SuccessCallback<Data>?,
                            onFailure: FailureCallback? = nil) -> Request

    Parameters

    queue

    A Queue instance. If no queue is specified it uses the default one.

    responseType

    The type of the model that will be deserialized and will be passed to the success block.

    progress

    specifies a progress callback to get upload progress updates.

    onSuccess

    specifies a success callback of type SuccessCallback.

    onFailure

    specifies a failure callback of type FailureCallback.

    Return Value

    The Request object.

  • Adds a request to a queue and starts an upload process for Decodable types.

    Declaration

    Swift

    @discardableResult
    public func startUpload<T: Decodable>(queue: Queue? = Queue.shared,
                                          responseType: T.Type,
                                          progressUpdate: ProgressCallbackType?,
                                          onSuccess: SuccessCallback<T>?,
                                          onFailure: FailureCallback? = nil) -> Request

    Parameters

    queue

    A Queue instance. If no queue is specified it uses the default one.

    responseType

    The type of the model that will be deserialized and will be passed to the success block.

    progress

    specifies a progress callback to get upload progress updates.

    onSuccess

    specifies a success callback of type SuccessCallback.

    onFailure

    specifies a failure callback of type FailureCallback.

    Return Value

    The Request object.

  • Adds a request to a queue and starts its execution for Transformer types.

    Declaration

    Swift

    @discardableResult
    public func startUpload<FromType: Decodable, ToType>(queue: Queue? = Queue.shared,
                                                         transformer: Transformer<FromType, ToType>.Type,
                                                         progressUpdate: ProgressCallbackType?,
                                                         onSuccess: SuccessCallback<ToType>?,
                                                         onFailure: FailureCallback? = nil) -> Request

    Parameters

    queue

    A Queue instance. If no queue is specified it uses the default one.

    transformer

    The transformer object that handles the transformation.

    progress

    specifies a progress callback to get upload progress updates.

    onSuccess

    specifies a success callback of type SuccessCallback.

    onFailure

    specifies a failure callback of type FailureCallback.

    Return Value

    The Request object.

  • Adds a request to a queue and starts its execution for String types.

    Declaration

    Swift

    @discardableResult
    public func startDownload(queue: Queue? = Queue.shared,
                              filePath: String,
                              progressUpdate: ProgressCallbackType?,
                              onSuccess: DownloadSuccessCallback?,
                              onFailure: FailureCallback? = nil) -> Request

    Parameters

    queue

    A Queue instance. If no queue is specified it uses the default one.

    filePath

    The destination file path to save the file.

    responseType

    The type of the model that will be deserialized and will be passed to the success block.

    progress

    specifies a progress callback to get upload progress updates.

    onSuccess

    specifies a success callback of type SuccessCallback.

    onFailure

    specifies a failure callback of type FailureCallback.

    Return Value

    The Request object.

  • Undocumented

    Declaration

    Swift

    public func copy(with zone: NSZone? = nil) -> Any
  • Reads the response headers from request after its completion.

    Declaration

    Swift

    func responseHeaders(_ headersCallback: @escaping ([String : String]?, TNError?) -> Void)

    Parameters

    headersCallback

    A closure that provides the response headers or an error.