TRON
open class TRON : TronDelegate
TRON
is a root object, that serves as a provider for single API endpoint. It is used to create and configure instances of APIRequest
and MultipartAPIRequest
.
You need to hold strong reference to TRON
instance while your network requests are running.
-
URL builder to be used by default in all requests. Can be overridden for specific requests.
Declaration
Swift
open var urlBuilder: URLBuilder
-
Global property, that defines whether stubbing is enabled. It is simply set on each
APIRequest
instance and can be reset.Declaration
Swift
open var stubbingEnabled: Bool
-
Global plugins, that will receive events from all requests, created from current TRON instance.
Declaration
Swift
open var plugins: [Plugin]
-
Default parameter encoding, that will be set on all APIRequests. Can be overrided by setting new value on APIRequest.parameterEncoding property. Default value - URLEncoding.default
Declaration
Swift
open var parameterEncoding: Alamofire.ParameterEncoding
-
Queue, used to deliver result completion blocks. Defaults to dispatch_get_main_queue().
Declaration
Swift
open var resultDeliveryQueue: DispatchQueue
-
CodableSerializer
for currentTRON
instance.Declaration
Swift
open lazy var codable: CodableSerializer { get set }
-
Alamofire.Session instance used to send network requests
Declaration
Swift
public let session: Alamofire.Session
-
Initializes
TRON
with given base URL, Alamofire.Session instance, and array of global plugins.Declaration
Swift
public init(baseURL: String, buildingURL: URLBuilder.Behavior = .appendingPathComponent, session: Alamofire.Session = .default, plugins: [Plugin] = [])
Parameters
baseURL
Base URL to be used
buildingURL
Behavior to use while building URLs. Defaults to .appendingPathComponent.
session
Alamofire.Session instance that will send requests created by current
TRON
plugins
Array of plugins, that will receive events from requests, created and managed by current
TRON
instance. -
Creates APIRequest with specified relative path and type RequestType.Default.
Declaration
Swift
open func request<Model, ErrorModel: ErrorSerializable, Serializer: DataResponseSerializerProtocol> (_ path: String, responseSerializer: Serializer) -> APIRequest<Model, ErrorModel> where Serializer.SerializedObject == Model
Parameters
path
Path, that will be appended to current
baseURL
.responseSerializer
object used to serialize response.
Return Value
APIRequest instance.
-
Creates APIRequest with specified relative path and type RequestType.UploadFromFile.
Declaration
Swift
open func upload<Model, ErrorModel: ErrorSerializable, Serializer: DataResponseSerializerProtocol> (_ path: String, fromFileAt fileURL: URL, responseSerializer: Serializer) -> UploadAPIRequest<Model, ErrorModel> where Serializer.SerializedObject == Model
Parameters
path
Path, that will be appended to current
baseURL
.fileURL
File url to upload from.
responseSerializer
object used to serialize response.
Return Value
APIRequest instance.
-
Creates APIRequest with specified relative path and type RequestType.UploadData.
Declaration
Swift
open func upload<Model, ErrorModel: ErrorSerializable, Serializer: DataResponseSerializerProtocol> (_ path: String, data: Data, responseSerializer: Serializer) -> UploadAPIRequest<Model, ErrorModel> where Serializer.SerializedObject == Model
Parameters
path
Path, that will be appended to current
baseURL
.data
Data to upload.
responseSerializer
object used to serialize response.
Return Value
APIRequest instance.
-
Creates APIRequest with specified relative path and type RequestType.UploadStream.
Declaration
Swift
open func upload<Model, ErrorModel: ErrorSerializable, Serializer: DataResponseSerializerProtocol> (_ path: String, from stream: InputStream, responseSerializer: Serializer) -> UploadAPIRequest<Model, ErrorModel> where Serializer.SerializedObject == Model
Parameters
path
Path, that will be appended to current
baseURL
.stream
Stream to upload from.
responseSerializer
object used to serialize response.
Return Value
APIRequest instance.
-
Creates MultipartAPIRequest with specified relative path.
Declaration
Swift
open func uploadMultipart<Model, ErrorModel, Serializer> (_ path: String, responseSerializer: Serializer, encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold, fileManager: FileManager = .default, formData: @escaping (MultipartFormData) -> Void) -> UploadAPIRequest<Model, ErrorModel> where ErrorModel: ErrorSerializable, Serializer: DataResponseSerializerProtocol, Serializer.SerializedObject == Model
Parameters
path
Path, that will be appended to current
baseURL
.responseSerializer
object used to serialize response.
formData
Multipart form data creation block.
Return Value
MultipartAPIRequest instance.
-
Creates APIRequest with specified relative path and type RequestType.Download.
Seealso
Alamofire.Request.suggestedDownloadDestination(directory:domain:)
method.Declaration
Swift
open func download<Model, ErrorModel: DownloadErrorSerializable, Serializer: DownloadResponseSerializerProtocol> (_ path: String, to destination: @escaping DownloadRequest.Destination, responseSerializer: Serializer) -> DownloadAPIRequest<Model, ErrorModel> where Serializer.SerializedObject == Model
Parameters
path
Path, that will be appended to current
baseURL
.destination
Destination for downloading.
responseSerializer
object used to serialize response.
Return Value
APIRequest instance.
-
Creates APIRequest with specified relative path and type RequestType.DownloadResuming.
Seealso
Alamofire.Request.suggestedDownloadDestination(directory:domain:)
method.Declaration
Swift
open func download<Model, ErrorModel: DownloadErrorSerializable, Serializer: DownloadResponseSerializerProtocol> (_ path: String, to destination: @escaping DownloadRequest.Destination, resumingFrom: Data, responseSerializer: Serializer) -> DownloadAPIRequest<Model, ErrorModel> where Serializer.SerializedObject == Model
Parameters
path
Path, that will be appended to current
baseURL
.destination
Destination to download to.
resumingFrom
Resume data for current request.
responseSerializer
object used to serialize response.
Return Value
APIRequest instance.
-
Creates
CodableSerializer
with currentTRON
instance and specificmodelDecoder
.Declaration
Swift
open func codable(modelDecoder: JSONDecoder) -> CodableSerializer