Latest 0.3.2
Homepage https://github.com/LucasBest/GenAPI
License MIT
Platforms ios 10.0
Dependencies ObjectDecoder
Authors

Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

GenAPI utilizes Swift generics for you to easily define the return types of your API calls.

let userAPIObject = APIObject<User, DefaultError>(success: { (user) in
    print(user)
}, failure:{ (apiError) in

})

userAPIObject.baseURL = URL(string:"https://jsonplaceholder.typicode.com")
userAPIObject.endPoint = "/users/1"

userAPIObject.debugOptions = .printDetailedTransaction

userAPIObject.get()

All that is required is that your return types conform to the protocol Modelable. However if you already have your models conforming to Apple’s Decodable protocol, all you have to do is change the conformance from Decodable to DecodableModel and your models will be ready to use with GenAPI.

struct User : DecodableModel{
    struct Company : DecodableModel{
        var name:String
        var catchPhrase:String
    }

    var id:Int
    var name:String?
    var company:Company?
}

The APIError enum breaks down any error that occurs into 1 of 3 different possibilities:

  • a session error
  • a parsing error
  • or an API error

A session error is returned if there is an error with the Session.
A parsing error is returned if an error is thrown when trying to decode either the Response type OR the Error type. (The parse error is most commonly a DecodingError.)
An API error is returned if the HTTP status code of the response is determined to be outside of the success range.

The APIObject class has many convenience functions to easily manipulate the underlying URLRequest, but the request is also publicly available in case you need to do any custom configuration. Simply access with APIObject.request.

Installation

GenAPI is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'GenAPI'

Author

Lucas Best, [email protected]

License

GenAPI is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "GenAPI",
    "version": "0.3.2",
    "summary": "GenAPI is lightweight, Swift, Generics based library for consuming REST APIs.",
    "description": "Use GenAPI to easily consume REST API's in a way that takes advantage of Swift Generics.",
    "homepage": "https://github.com/LucasBest/GenAPI",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Lucas Best": "[email protected]"
    },
    "source": {
        "git": "https://github.com/LucasBest/GenAPI.git",
        "tag": "0.3.2"
    },
    "social_media_url": "https://twitter.com/thereallu5",
    "swift_version": "5.0",
    "platforms": {
        "ios": "10.0"
    },
    "source_files": "GenAPI/Classes/**/*",
    "dependencies": {
        "ObjectDecoder": []
    }
}

Pin It on Pinterest

Share This