HTTPTransaction
open class HTTPTransaction<HTTPResponseDataType>: DataTransaction
A DataTransaction that uses a URLRequest to request data from
(and potentially send data to) an HTTP(S)-based service.
A successful transaction produces an instance of ResponseDataType.
-
The
CacheStorageHookthat will be passed theResponseDataTypewhen a transaction completes successfully.Declaration
Swift
public var storeInCache: CacheStorageHook? -
The signature of a function to be called upon successful completion of a transaction, to allow cache storage of the transaction response.
Declaration
Swift
public typealias CacheStorageHook = (HTTPTransaction<ResponseDataType>, ResponseDataType, HTTPResponseMetadata) -> Void -
The signature of a function used to configure the
URLRequestprior to issuing the transaction.Declaration
Swift
public typealias RequestConfigurator = (HTTPTransaction<ResponseDataType>, inout URLRequest) throws -> Void -
The signature of a function used to validate the response received by an HTTP transaction.
Declaration
Swift
public typealias ResponseValidator = (HTTPTransaction<ResponseDataType>, HTTPURLResponse, HTTPResponseMetadata, Data) throws -> Void -
The signature of a function used to construct
URLinstances for the transaction.Declaration
Swift
public typealias URLConstructor = (HTTPTransaction<ResponseDataType>) throws -> URL -
If the payload processor succeeds, the results are passed to the payload validator, giving the transaction one final chance to sanity-check the data and bail if there’s a problem.
Declaration
Swift
public typealias PayloadValidator = (HTTPTransaction<ResponseDataType>, ResponseDataType, Data, HTTPResponseMetadata) throws -> Void -
The signature of a function used to construct
URLRequests for the transaction.Declaration
Swift
public typealias RequestConstructor = (HTTPTransaction<ResponseDataType>, URL) throws -> URLRequest -
The signature of a payload processing function. This function accepts binary
Dataand attempts to convert it toResponseDataType.Declaration
Swift
public typealias PayloadProcessor = (HTTPTransaction<ResponseDataType>, Data, HTTPResponseMetadata) throws -> ResponseDataType -
Indicates the type of transaction provided by the implementation.
See moreDeclaration
Swift
public enum TransactionType -
The URL of the service to be used by the transaction.
Declaration
Swift
public let url: URL -
The HTTP request method to use for the transaction.
Declaration
Swift
public let method: HTTPRequestMethod -
Optional data to send to the service when executing the transaction.
Declaration
Swift
public let uploadData: Data? -
The MIME type of the
uploadData(if any). If present, this value is sent as HTTP request’sContent-Typeheader.Declaration
Swift
public let contentType: MIMEType? -
Indicates the type of transaction provided by the receiver.
Declaration
Swift
public let transactionType: TransactionType -
A function called to construct the
URLused for the transaction. The default implementation simply returns the value of the transaction’surlproperty.Declaration
Swift
public var constructURL: URLConstructor = { txn in -
A function called to construct the
URLRequestused to execute the transaction. The default implementation returns a simpleURLRequestconstructed from the passed-inURL.Declaration
Swift
public var constructRequest: RequestConstructor = { _, url in -
A function called to configure the
URLRequestprior to executing the transaction. The default implementation does nothing.Declaration
Swift
public var configureRequest: RequestConfigurator = { _, _ in } -
The
PayloadProcessorthat will be used to produce the receiver’sResponseDataTypeupon successful completion of the transaction.Declaration
Swift
public var processPayload: PayloadProcessor = { txn, data, _ in -
The
PayloadValidatorused to validate theResponseDataTypeproduced by thePayloadProcessorupon successful completion of the transaction.Declaration
Swift
public var validatePayload: PayloadValidator = { _, _, _, _ in } -
The
URLSessionConfigurationused to create theURLSessionfor the transaction.Declaration
Swift
public var sessionConfiguration: URLSessionConfiguration = .default -
A
ResponseValidatorfunction used to validate the HTTP response received when executing a transaction.Declaration
Swift
public var validateResponse: ResponseValidator = { _, resp, meta, data in -
Initializes a new transaction that will connect to the given service.
Declaration
Swift
public init(url: URL, method: HTTPRequestMethod? = nil, upload data: Data? = nil, contentType: MIMEType? = nil, transactionType: TransactionType = .api, processingQueue queue: DispatchQueue = .transactionProcessing) -
Initializes a new transaction that will connect to the given service.
Declaration
Swift
open func cancel() -
Configures the
URLRequest.Note
Subclasses overriding this function should call
super.Declaration
Swift
open func configure(request: inout URLRequest)Parameters
requestThe
URLRequestto configure. -
Configures the
URLRequest.Note
Subclasses overriding this function should call
super.Declaration
Swift
open func executeTransaction(completion: @escaping Callback)Parameters
completionA function that will be called upon completion of the transaction.
-
Declaration
Swift
open func transactionCompleted(_ result: Result)Parameters
resultThe instance of
ResponseDataTypethat resulted from the transaction.
View on GitHub
HTTPTransaction Class Reference