Skip to content

Releases: ishkawa/APIKit

2.0.0

23 May 00:21
Compare
Choose a tag to compare

🎉

APIKit 2 introduces 3 major features below:

  • New error handling model
  • Convenience parameters and actual parameters
  • Abstraction of networking backend

See the migration guide and following summary for more details.

New error handling model

The error type of Session.sendRequest(_:) is changed to SessionTaskError:

public enum SessionTaskError: ErrorType {
    case ConnectionError(ErrorType)
    case RequestError(ErrorType)
    case ResponseError(ErrorType)
}

These error cases describes where the error occurred, not what is the error. You can throw any kind of error to notify what is happened in the following methods:

public protocol RequestType {
    ...

    // The error thrown here will be the associated value of SessionTaskError.RequestError 
    func interceptURLRequest(URLRequest: NSMutableURLRequest) throws -> NSMutableURLRequest

    // The error thrown here will be the associated value of SessionTaskError.ResponseError 
    func interceptObject(object: AnyObject, URLResponse: NSHTTPURLResponse) throws -> AnyObject
}

Convenience parameters and actual parameters

Usually, you can specify request parameters in dictionary-literal or array-literal like below:

struct SomeRequest: RequestType {
    ...

    var parameters: AnyObject? {
        return ["q": "Swift"]
    }
}

var parameters is the convenience parameters. It is define as below:

public protocol RequestType {
    ...

    var parameters: AnyObject? { get }
}

Actually, we have to translate the literal into HTTP/HTTPS request. There are 2 places to express parameters, URL query and body. RequestType has interface to express them, var queryParameters: [String: AnyObject]? and var bodyParameters: BodyParametersType?. Those are the actual parameters.

public protocol RequestType {
    ...

    var queryParameters: [String: AnyObject]? { get }
    var bodyParameters: BodyParametersType? { get }
}

If you implement convenience parameters only, the actual parameters are computed from the convenience parameters depending on HTTP method.

APIKit provides 3 types that conforms to BodyParametersType:

Name Parameters Type
JSONBodyParameters AnyObject
FormURLEncodedBodyParameters [String: AnyObject]
MultipartFormDataBodyParameters [MultipartFormDataBodyParameters.Part]

Abstraction of networking backend

APIKit uses NSURLSession as networking backend by default. Since Session in APIKit 2 has abstraction layer of backend called SessionAdapterType, you can change the backend of Session like below:

Demo implementation of Alamofire adapter is available here.

2.0.0-beta.7

19 May 16:57
Compare
Choose a tag to compare
2.0.0-beta.7 Pre-release
Pre-release
  • [Fixed] Use the return value of interceptURLRequest(_:).

1.4.1: Use the return value of configureURLRequest(_:)

19 May 16:30
Compare
Choose a tag to compare

2.0.0-beta.6

18 May 01:02
Compare
Choose a tag to compare
Update podspec

2.0.0-beta.5

16 May 17:04
Compare
Choose a tag to compare
2.0.0-beta.5 Pre-release
Pre-release
  • [Renamed] HTTPHeaderFields in RequestType is renamed to headerFields.
  • [Renamed] resumedTaskWithURLRequest(_:) is renamed to createTaskWithURLRequest(_:).
  • [Added] resume() is added to SessionTaskType.
  • [Added] StringDataParser is added for unformatted response body.
  • [Changed] Exposed RequestError.
  • [Changed] Type of associated value of SessionTaskError.ConnectionError is changed from NSError to ErrorType.

2.0.0-beta.4

06 May 12:25
Compare
Choose a tag to compare
2.0.0-beta.4 Pre-release
Pre-release
  • MultipartFormDataParameters uses NSInputStream for its entity. #160
  • Session.sharedSession is changed to class property for overriding. #158
  • Add callbackQueue parameter to Session.sendRequest(). #157 #156

Thanks to @jyounus and @kumabook for the contribution!

1.4.0: Extensible shared session

04 May 13:24
Compare
Choose a tag to compare
  • Session.sharedSession is now class property so that you can override it. #158

2.0.0-beta.3

27 Mar 18:13
Compare
Choose a tag to compare
2.0.0-beta.3 Pre-release
Pre-release
  • Migrate to Swift 2.2 syntax.

1.3.0: Swift 2.2

27 Mar 17:06
Compare
Choose a tag to compare
  • Migrate to Swift 2.2 syntax.

2.0.0-beta.2

21 Mar 21:46
Compare
Choose a tag to compare
2.0.0-beta.2 Pre-release
Pre-release
  • Fixed CocoaPods spec.

NOTE: Since APIKit 2 is beta software, breaking changes will continue to occur.