We shipped Alamofire 5.2.0 today with two major features and a variety of other enhancements and bug fixes.
Combine Support
Alamofire now includes three types of Publisher
that can be used to publish responses from all Alamofire requests. This means that Alamofire has support for parallel and sequential requests for the first time. If you've used Alamofire before, the syntax should be very familiar, as the publisher just replaces the closure-based response handlers in the request chain.
AF.request("https://httpbin.org/get")
.publishDecodable(type: HTTPBinResponse.self)
This produces a DataResponsePublisher
that will automatically start the request when a subscriber is added and provide a single DataResponse<HTTPBinResponse, AFError>
value. These values can then be transformed using any Combine operator, as well as a few built in modifiers that can pull the Result
value or create a value stream.
AuthenticationInterceptor
AuthenticationInterceptor
is a RequestInterceptor
designed to automatically handle applying authentication to URLRequest
s as well as retrying failed requests, with users providing only the base logic necessary to apply and refresh. AuthenticationInterceptor
takes care of the hard part of enqueuing retries while waiting for a refresh, handling all of the thread-safety for you automatically. Users just need to provide a type conforming to the Authenticator
protocol, which provides the AutenticationInterceptor
with the logic it needs.
Our documentation includes a brief example of what that would look like for OAuth2.
More Flexible Response Handlers
Alamofire 5.2.0 also adds the ability to pass all serializer parameters through response handlers, so you can customize the serializer without having to create a separate instance.
DisabledEvaluator
Renamed to DisableTrustEvaluator
This rename has deprecated the old name but the type is unchanged. However, it's usually a better idea to enable the trust of your self signed certificates than to disable trust evaluation, so this type should only be a last resort.
Interceptor
Can Now Be Composed of Multiple RequestInterceptor
s
The Interceptor
type has been enhanced to handle multiple RequestInterceptor
instances, in addition to separate RequestAdapter
and RequestRetrier
instances. This should make it much easier to compose multiple RequestInterceptor
s together.