Alamofire 5.5.0 Released!

Alamofire 5.5 is the first release where we're labeling features we consider experimental. These features, while fully designed and well tested, rely on language or framework features which may change or require breaking bug fixes, and we'd rather not have to make a major release in that case. So [:fire: Experimental :fire:] features may require breaking changes in minor, rather than major, releases. This will be rare and compatibility should be preserved in most cases, but cannot be guaranteed.

All issues associated with this milestone can be found using this filter.

Added

  • [:fire: Experimental :fire:] support for Swift Concurrency, including async-await for requests and StreamOf for streaming values.
  • Generic static accessors for various protocols types for Swift 5.5.
  • .indexInBrackets options for array encoding in query parameters.
  • RequestAdapterState and new protocol requirements for RequestAdapter to allow for additional state to be available.

Updated

  • Session to more safely target provided custom DispatchQueues for internal use.
  • AFError message regarding unacceptable Content-Types to sort the types.
  • Base Swift language version requirement to 5.3.
  • Sample app to show proper loading state for requests.

Deprecated

  • responseJSON and associated methods, in preference to responseDecodable.

Fixed

4 Likes

Alamofire 5.5's concurrency support supports awaiting the full response, result, or throwing value of a request.

let task = AF.request(...).serializingDecodable(Type.self)
let response = await task.response
let result = await task.result
let value = try await task.value

Convenience methods have also been added for the various asynchronous state producers, like onURLSessionTaskCreation.

let request = session.request(...)
async let uploadProgress = request.uploadProgress().collect()
async let downloadProgress = request.downloadProgress().collect()
async let requests = request.urlRequests().collect()
async let tasks = request.urlSessionTasks().collect()
async let descriptions = request.cURLDescriptions().collect()
async let response = request.serializingDecodable(TestResponse.self).response
let values: (uploadProgresses: [Progress],
             downloadProgresses: [Progress],
             requests: [URLRequest],
             tasks: [URLSessionTask],
             descriptions: [String],
             response: AFDataResponse<TestResponse>)
values = await (uploadProgress, downloadProgress, requests, tasks, descriptions, response)

Alamofire 5.5 also now allows extremely compact usage with static accessors for our protocol types in Swift 5.5.

Previously

AF.request("https://httpbin.org/post",
            method: .post,
            parameters: Value(),
            encoder: JSONParameterEncoder(),
            interceptor: RetryPolicy())
    .response(responseSerializer: DecodableResponseSerializer<TestResponse>()) { response in
         debugPrint(response)
    }

Now

AF.request("https://httpbin.org/post",
           method: .post,
           parameters: Value(),
           encoder: .json,
           interceptor: .retryPolicy)
    .response(responseSerializer: .decodable(of: TestResponse.self)) { response in
        debugPrint(response)
    }
Terms of Service

Privacy Policy

Cookie Policy