All notable changes to this project will be documented in this file.
let request: APIRequest<Int,APIError> = tron.codable
.request("status/200")
let result = try await request.sender().value
Swift Concurrency methods require Swift 5.5 / Xcode 13.2 / iOS 13 / tvOS 13 / macOS 10.15 / watchOS 6.
Read more usage examples in README
download(_:to:)
anddownload(_:to:resumingFrom:)
methods that createDownloadAPIRequest
with <URL, ErrorModel> generic constraints to simplify requests creation, where you need only URL from resulting operation.- Structured Concurrency support for Swift 5.5 and higher:
RequestSender
,DownloadRequestSender
types.
- Issue, that could lead to sending network request with api stubs enabled, but Session.startRequestsImmediately property was set to false.
- New deployment targets: iOS 11 / tvOS 11 / macOS 10.13 / watchOS 4 / Xcode 13. OS deployment targets now match minimum deployment targets, supported by Xcode 14.
- Improve Combine extensions to work better with stubs, that return synchronously.
- Swift 5.4 warnings
- RxSwift dependency bumped to 6.0 and higher
- Ability to modify
URLRequests
before it's adapted and sent:
tron.codable
.request("status")
.modifyRequest { $0.httpShouldHandleCookies = false }
This feature uses Alamofire.RequestModifier closure, that can also be set without DSL on request instance directly:
let request : APIRequest<Post,Empty> = tron.codable.request("posts")
request.requestModifier = { urlRequest in
urlRequest.httpShouldHandleCookies = false
}
- Combine support on supported platforms through
publisher()
method onAPIRequest
,UploadAPIRequest
,DownloadAPIRequest
. APIError.isCancelled
property, that tells, whether request, that errored, was cancelled by sender.
Alamofire.ParameterEncoding
,JSONEncoding
andURLEncoding
are now exposed through TRON API and don't require importing Alamofire to use.
NetworkActivityPlugin
is deprecated on iOS 13 and higher, becauseUIApplication.isNetworkActivityIndicatorVisible
property it has been switching is deprecated on iOS 13 and higher.
- Several
Alamofire
types that are exposed through TRON API's are now implicitly exported to allow using them without needing to writeimport Alamofire
. SeeExports.swift
file for a list of them.
FileURLPassthroughResponseSerializer
, which can be used as a response serializer forDownloadAPIRequest
when you are only interested in URL of downloaded file.
NetworkLoggerPlugin
now correctly skips cancelled requests
- Added
DownloadAPIRequest.perform(withSuccess:failure:)
method, similar toAPIRequest
andUploadAPIRequest
methods.
BaseRequest.headers
now default toHTTPHeaders.default
to allow sending Alamofire default headers such as "Accept-Language", "Accept-Encoding", "User-Agent".
- Better debug prints for
NetworkLoggerPlugin
when decoding usingCodable
protocol. configure(_:)
method forBaseRequest
DSL to allow configuring request with several changes at once.
- Plugin API that previously was called with
Alamofire.Data/DownloadResponse<Model, Error>
is now called withAlamofire.Data/DownloadResponse<Model, AFError>
due to Alamofire changes to error handling. performCollectingTimeline(withCompletion:)
method is now called also withAFError
instead ofError
.
- Support for per-request Interceptors.
- Three different behaviors for building URLs:
.appendingPathComponent
,.relativeToBaseURL
and.custom
. Those can be set in TRON initializer:
let tron = TRON(baseURL: "https://www.example.com/", buildingURL: .relativeToBaseURL)
Or you can change URLBuilder.Behavior
on per-request basis, using the new DSL:
let request: APIRequest<Int,APIError> = tron.swiftyJSON
.request("status/200")
.buildURL(.relativeToBaseURL)
Default behavior for TRON is .appendingPathComponent
.
URLBuildable
protocol. Please use different behaviors forURLBuilder
instead.
- Support for Swift Package Manager in Xcode 11
- New convenient DSL, that allows to convert this code:
func deleteSession() -> APIRequest<Empty, UnknownError> {
let request : APIRequest<Empty, UnknownError> = tron.codable.request("session")
request.method = .delete
return request
}
into:
func deleteSession() -> APIRequest<Empty, UnknownError> {
return tron.codable.request("session").delete()
}
Read more about other DSL improvements in 5.0 Migration Guide
URLBuilder
now resolves URL's usingURL(string:relativeTo:)
method, thus allowing more flexible url creation.
- Ability to traverse json to any level when using SwiftyJSONDecodable.
- Improved response serializer behavior for cases where requests were stubbed using URLProtocol.
- TRON 5 requires RxSwift 5 and SwiftyJSON 5
Core
is now a default subspec for CocoaPods installation method. To use SwiftyJSON, add following to Podfile:
pod 'TRON/SwiftyJSON'
ErrorSerializable
protocol changed to have non-optional initializer and to not acceptserializedObject
. It no longer can be used for additional object validation, but behavior should be more predictable and straightforward -ErrorSerializable
should only be created if somebody (URL loading system, Alamofire or Model serialization) actually reported error.codable
is now a lazy stored property instead of computed property.CodableSerializer
API has been made open to allow easy customization in subclasses.NetworkLoggerPlugin
now has a constructor that allows to easily configure it's behavior.
- Properties that worked with
Alamofire.SessionManager
have been renamed tosession
to be in line withAlamofire
renaming ofSessionManager
toSession
.
TRON.defaultAlamofireManager()
method. TRON initializer now usesAlamofire.Session.default
as a replacement.TRON.processingQueue
property
TRON now requires:
- Xcode 10
- Swift 4 and higher
- iOS/tvOS 10 and higher
- watchOS 3 and higher
- macOS 10.12 and higher
- Complete documentation
TRONDataResponseSerializer
andTRONDownloadResponseSerializer
structs to encapsulate serialization of responses using closure.- All test suite now uses
StubbingURLProtocol
to stop tests from sending network requests. Closes #21. - Additional
JSONDecodable
conformances have been added for arithmetic types such asInt8...Int64
,UInt8...64
.
EmptyResponse
type was replaced withAlamofire.Empty
struct to not interfere withAlamofire.EmptyResponse
protocol.TRON.stubbingShouldBeSuccessful
property since now each stub directly defines it's behavior instead of global setting- Conditional conformance of
Array
toJSONDecodable
- Convenience download methods on
CodableSerializer
andJSONDecodableSerializer
AuthorizationRequirement
enum. Please useAlamofire.RequestAdapter
andSession.adapter
property to adapt request, when additional headers are needed.HeaderBuildable
protocol andHeaderBuilder
types. Please useBaseRequest.headers
property of typeAlamofire.HTTPHeaders
directly.ErrorHandlingDataResponseSerializerProtocol
andErrorHandlingDownloadResponseSerializer
protocol. Now,ErrorModel
on all requests conforms toErrorSerializable
protocol, that contains initializer that allows to create it directly.CodableDownloadParser
andJSONDecodableDownloadParser
, replacement classDownloadSerializer
has been introduced, it allows to create a data model by implementingDownloadResponseSerializerProtocol
UploadAPIRequest.performMultipart
method, because multipart upload is no longer a special case inAlamofire 5
, please useUploadAPIRequest.perform
instead.
headers
property ofBaseRequest
now containsHTTPHeaders
type instead of[String: String]
. Please note that along withHeaderBuilder
removal TRON no longer sends 'Accept':'application/json' header by default.APIError
is changed to be able to acceptSerializedObject
and is now a class with nullable initializer. Also,DownloadAPIError
type has been introduced for download errors, that do not haveData
in them, but havefileURL
instead.Plugin
methods that previously acceptedAPIError<ErrorModel>
now acceptErrorModel
directly. AddeddidSuccessfullyParseDownloadResponse
anddidReceiveDownloadResponse
methods.- All concrete implementations of
DataResponseSerializerProtocol
such asCodableParser
andJSONDecodableParser
now have only one generic argument -Model
and are only parsing model type. JSONDecodableParser
andCodableParser
now have only one generic argument -Model
, sinceErrorModel
is now moved toErrorSerializable
protocol, that does not depend on any particular serializer.APIStub
has been rewritten from scratch to allow injecting only results of network request(URLRequest
,HTTPURLResponse
,Data
,Error
andfileURL
) as opposed to actualModel
anderrorModel
as well as definition of successful/unsuccessful requests.APIStub
now is been attached toAlamofire.Request
when stubbing for this particular request has been enabled. Rewrite also allows plugin callbacks to be called more consistently for both stubbed and unstubbed cases.rxMultipartResult
method onUploadRequest
method was removed sinceUploadRequest
for multipart requests in Alamofire 5 is now synchronous and now does not require special handling. You can now callrxResult
replacement method instead.
UploadAPIRequest
now callsdidReceiveDataResponse
plugin methods when sending multipart-form requests.
- Implemented
JSONDecodable
support for Arrays, whose Element is JSONDecodable. Requires Swift 4.1 to work.
- Improved output of
NetworkLoggerPlugin
, which now includes status codes, HTTP body contents, and some emojis 🚀
- Allow
EmptyResponse
to be used with CodableParser when network response does not contain valid JSON.
- Deprecate TRON level headerBuilder in favor of Alamofire.requestAdapter.
- Loosen CodableParser generic constraints to be able to work with
Decodable
protocol instead ofCodable
.
- Compiled with Xcode 9.1 / Swift 4.0.2
- RxSwift dependency is bumped up to 4.0.0-beta.0, SwiftyJSON dependency is bumped to
4.0.0-alpha.1
- Binary release is compiled with Xcode 9.0 Swift 4 compiler.
- Added ability to customize
JSONSerialization.ReadingOptions
forJSONDecodableSerializer
. Unlike previous releases, no options are specified by default(Previously SwiftyJSON usedallowFragments
option).
To have old behavior that allows fragmented json, use:
let request = tron.swiftyJSON(readingOptions: .allowFragments).request("path")
- Added ability to customize
JSONDecoder
forCodableSerializer
for both model parsing and error parsing. CodableParser
andJSONDecodableParser
are now classes, that are subclassible.
This is major release, containing breaking API changes, please read TRON 4.0 Migration Guide
- Implemented support for
Codable
protocol. APIError
now takes it's localizedDescription from underlyingerrorModel
if that model isLocalizedError
, and fromerror.localizedDescription
if not.
SwiftyJSONDecodable
methods are now prefixed with .swiftyJSON, like so:
// old
let request = tron.request("path")
// new
let request = tron.swiftyJSON.request("path")
- Makes
NetworkActivityPlugin
always use API from the main thread(thanks, @mgurreta)!
- Preliminary support for Swift 3.2 and Swift 4(Xcode 9 beta 6).
- Prevent upload requests from being sent using
performMultipart
method if they are not of .multipartFormData type and vice versa, add specific assertions and error messages. - Added
isMultipartRequest
property onUploadRequestType
.
- Improved SPM integration and CI scripts
- Added
validationClosure
properties onAPIRequest
,DownloadAPIRequest
andUploadAPIRequest
that allow customizing validation behaviour. Default behaviour, as before, is callingvalidate()
method onRequest
.
- Constructors on
APIRequest
,UploadAPIRequest
,APIStub
are made public to allow overriding in subclasses.
dispatchQueue
property was removed fromPlugin
protocol. AllPlugin
events are now called synchronously to allow write access to objects, expecially requests. IfPlugin
requires any specific dispatch queue to run on, it must implement this logic itself.
APIStub
will now print error to console, if it failed to build model from file.NetworkLoggerPlugin
will no longer double escape characters, when printing successful request cURL to console.
Lowers deployment targets to iOS 8 / macOS 10.10
Required dependencies: Alamofire 4.1 and higher.
NetworkLoggerPlugin
now haslogCancelledRequests
property, that allows turning off logging of failing requests, that were explicitly cancelled by developer.- Ensures, that
APIStub
always calls completion blocks, even if response is not successfully created.
APIStub
creation is deferred untilapiStub
property is called.APIStub
model
anderror
properties have been replaced withmodelClosure
anderrorClosure
, that are created inAPIStub
constructor. This is done to allowAPIStub
to function even ifAPIRequest
has been deallocated.
- Plugin protocol was rewritten to contain generic methods and more information about what is happening in TRON ecosystem.
ErrorHandlingDataResponseSerializerProtocol
andErrorHandlingDownloadResponseSerializerProtocol
now have protocol extensions for default SwiftyJSON error parsing.
Parseable
protocol was rewritten to directly inherit fromAlamofire.DataResponseSerializerProtocol
. It allows us to have two generic typealiases -SerializedObject
fromAlamofire
and added to itSerializedError
from TRON.- Fixed issue, that could cause completion handlers to be called on background thread.
- Use SwiftyJSON instead of forked SwiftyJSON3
parameters
property onBaseRequest
now contains [String:Any] instead of [String:AnyObject]processingQueue
property onAPIRequest
was removed.
- Rewrite
Parseable
protocol using associatedtype.
TRON
2.0 is supported on iOS 9.0, macOS 10.11 and higher due to Alamofire.framework required versions. Read [migration guide](/Docs/2.0 Migration Guide.md) for overview of API changes.
NOTE This release uses forked SwiftyJSON, and SwiftyJSON3
cocoapod, because original repo has not been updated to Swift 3. In future release we hope to use SwiftyJSON
cocoapod. Link
ResponseParseable
was rewritten and renamed toParseable
. It now allows creating models without using a constructor. Therefore, it's now possibly to use really any kind of mapper and make factory-like response builders.- Success blocks on
APIRequest
are now optional and equal to nil by default. MultipartAPIRequest
now becomes a part of largerUploadAPIRequest
class.- Introduced new
DownloadAPIRequest
class, that receives part ofAPIRequest
functionality.
- Swift 3 API design guidelines have been applied to all API.
perform(completion:)
method was renamed toperformCollectingTimeline(withCompletion:)
to better match method internal behaviourencoding
property onTRON
and requests has been renamed toparameterEncoding
and now has a different type -Alamofire.ParameterEncoding
responseBuilder
property onAPIRequest
was removed, as it's no longer used when parsing received response.JSONDecodable
extension onArray
is temporarily unavailable due to issues with Swift compiler.encodingStrategy
property on TRON was removed - please useparameterEncoding
instead.TRON.RESTencodingStrategy
andTRON.URLEncodingStrategy
were removed - please refer to Alamofire 4 migration guide for details.RequestType
enum was replaced byUploadRequestType
andDownloadRequestType
onDownloadAPIRequest
andUploadAPIRequest
classes.
- Optional
progressClosure
parameter torxMultipartUpload
method for multipart requests
stubbingShouldBeSuccessful
property onTRON
, that allows setting up globally, will stubs succeed or not.encodingStrategy
property onTRON
instance, that is used to select encoding type based on HTTP Method.encodingStrategy
property onAPIRequest
, that will be filled withTRON
strategy on construction.
By default, for backwards compatibility reasons, we use ParameterEncoding.URL as a default strategy. This will change in next major release of TRON, which will use TRON.RESTEncodingStrategy
instead. This encoding strategy uses .JSON encoding for POST, PUT and PATCH requests, and .URL encoding for all other HTTP methods.
encoding
property onAPIRequest
. Please useencodingStrategy
property instead.
None.
If you haven't been following beta releases, please read [1.0.0 Migration Guide](/Docs/1.0 Migration Guide.md) to get an overview of new API additions and phylosophy behind some breaking changes that were made in this release.
ResponseParseable
protocol reworked to only include single initializer instead of associated typeModelType
. Therefore, all generic methods that previously acceptedModel.ModelType
type now acceptModel
type.- Removed
performWithSuccess(_:failure:)
method, please useperform(success:failure:)
method instead.
- Ability to create APIRequest with Array generic constraint, for example -
APIRequest<[Int],APIError>
ResponseParseable
initWithData:
method is now throwable, allowing parsed models to throw during initialization. When initializer throws,APIRequest
treats it as a parsing error.
ResponseParseable
protocol now accepts NSData instead ofAnyObject
in its constructor, allowing any kind of parsing, JSON/XML, you-name-it.
TRON 1.0 is a major release with a lot of new features and breaking changes. To find out more about philosophy of those and how to adapt to new API's, read [TRON 1.0 Migration Guide](/Docs/1.0 Migration Guide.md)
RequestToken
protocol removed, perform request methods now returnAlamofire.Request?
to allow customization. When request is stubbed, nil is returned.tron.multipartRequest(path:)
removed, usetron.uploadMultipart(path:formData:)
method insteadMultipartAPIRequest
performWithSuccess(_:failure:progress:cancellableCallback:)
method is replaced byperformMultipart(success:failure:encodingMemoryThreshold:encodingCompletion:)
MultipartAPIRequest
no longer subclassesAPIRequest
- they both now subclassBaseRequest
.appendMultipartData(_:name:filename:mimeType:)
onMultipartAPIRequest
is removed. Please useAlamofire.Manager.MultipartFormData
built-in methods to append multipart data- RxSwift extension on
MultipartAPIRequest
reworked to return single Observable EventDispatcher
class and correspondingTRON.dispatcher
,APIRequest.dispatcher
property are replaced byTRON
andAPIRequest
properties -processingQueue
andresultDeliveryQueue
, which are used to determine on which queue should processing be performed and on which queue results should be delivered.Progress
andProgressClosure
typealiases have been removed
upload(path:file:)
- upload from fileupload(path:data:)
- upload dataupload(path:stream:)
- upload from streamdownload(path:destination:)
- download file to destinationdownload(path:destination:resumingFromData:)
- download file to destination, resuming from datauploadMultipart(path:formData:)
- multipart form data uploadperform(completion:)
method, that acceptsAlamofire.Response
-> Void block.
APIRequest
performWithSuccess(_:failure:)
method is deprecated, new name -perform(success:failure:)
- Allow
MultipartAPIRequest
to use any StringLiteralConvertible value in parameters (for example Int, or Bool e.t.c).
- Prevent
APIRequest
from being deallocated if rxResult Observable is passed elsewhere without keeping strong reference toAPIRequest
itself.
- Plugins are now correctly notified with "willSendRequest(_:)" method call for multipart requests.
- Update to Swift 2.2. This release is not backwards compatible with Swift 2.1.
NetworkActivityPlugin
now acceptsUIApplication
in it's initializer to be able to compile in application extensions environments.NetworkActivityPlugin
supports only single instance ofTRON
. If you have multipleTRON
s in your application, consider building another plugin, that uses static variables to track number of requests, similar to oldNetworkActivityPlugin
from5639b960e968586d1e24a7adcc6a3420e8648d49
.
- Added
EmptyResponse
class that can be used for requests with empty body. For example:
let request : APIRequest<EmptyResponse, MyError> = tron.request("empty/response")
- RxSwift extensions for
APIRequest
andMultipartAPIRequest
, usage:
let request : APIRequest<Foo, MyError> = tron.request("foo")
_ = request.rxResult.subscribeNext { result in
print(result)
}
let multipartRequest = MultipartAPIRequest<Foo,MyError> = tron.multipartRequest("foo")
let (progress, result) = multipartRequest.rxUpload()
_ = progress.subscribeNext { progress in
print(progress.bytesSent,progress.totalBytesWritten,progress.totalBytesExpectedToWrite)
}
_ = result.subscribeNext { result in
print("Received result: \(result)")
}
Completion blocks are now handled by new EventDispatcher
class, which is responsible for running completion blocks on predefined GCD-queue.
Default behaviour - all parsing is made on QOS_CLASS_USER_INITIATED queue, success and failure blocks are called on main queue.
You can specify processingQueue
, successDeliveryQueue
and failureDeliveryQueue
on dispatcher
property of TRON. After request creation you can modify queues using dispatcher
property on APIRequest, or even replace EventDispatcher with a custom one.
Added public initializer for NetworkActivityPlugin
Add support for any custom mapper to be used with TRON. Defaulting to SwiftyJSON
.
Examples:
ResponseParseable
and JSONDecodable
are now Self-requirement protocols with all their limitations. Apart from that, there are some other limitations as well:
Subclassing ResponseParseable requires explicit typealias in subclassed model:
class Ancestor: JSONDecodable {
required init(json: JSON) {
}
}
class Sibling: Ancestor {
typealias ModelType = Sibling
}
Discussion in mailing Swift mailing lists
Current architecture does not support having more than one mapper in your project, because Swift is unable to differentiate between two ResponseParseable extensions on different types.
Currently, there's no way to extend CollectionType or Array with JSONDecodable
or ResponseParseable
protocol, so creating request with ModelType of array(APIRequest<[Foo],Bar>) is not possible.
Blocking radars: https://www.openradar.me/23433955 https://www.openradar.me/23196859
Initial OSS release, yaaaay!