Latest 0.2.4
Homepage https://github.com/johnpatrickmorgan/FireRoutes
License MIT
Platforms ios 9.0, requires ARC
Dependencies Alamofire
Authors

🔥 FireRoutes 🔥

Version
License
Swift

FireRoutes is a lightweight extension to Alamofire that simplifies network calls through the concept of a Route.

What is a Route?

A Route represents how a particular network call should be structured and how the response data should be transformed into a useable object. It conforms to two protocols from Alamofire: URLRequestConvertible and DataResponseSerializerProtocol.

A Route subclass can be defined like so:

let baseURL = "http://www.myserver.com/api"

class AvatarRoute: Route<UIImage> {

    init(userId: String) {
        super.init()
        request = GET(baseURL + "/avatar/(userId)_img.png")
        responseSerializer = DataRequest.imageResponseSerializer()
    }
}

This captures in a single class all of the client’s expectations of the avatar endpoint. Defining a number of routes in a single Routes.swift file provides a useful catalogue of all the endpoints your app may use.

The Route concept also simplifies the code that originates the request via an extension to Alamofire’s SessionManager:

manager.request(AvatarRoute(userID:"jmorgan")) { response in

    // compiler infers response.result.value to be of UIImage type
}

The compiler infers the correct Result type, keeping your code clean and simple.

Custom Response Serialization

Despite its simple approach, FireRoutes retains all the flexibility of URLRequestConvertible and DataResponseSerializerProtocol. You can use it in conjunction with other Alamofire extensions such as AlamofireObjectMapper to generate custom model objects…

class MappedModelRoute: Route<MappedModel> {

    override init() {
        super.init()
        request = GET(baseURL + "/model")
        responseSerializer = DataRequest.ObjectMapperSerializer(nil)
    }
}

…which means the response will be parsed and mapped into your custom model object:

manager.request(MappedModelRoute()) { response in

    // compiler infers response.result.value to be of MappedModel type
}

Installation

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

pod 'FireRoutes'

License

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

Latest podspec

{
    "name": "FireRoutes",
    "version": "0.2.4",
    "summary": "A lightweight extension to Alamofire to simplify API calls.",
    "description": "FireRoutes introduces the concept of a Route. A Route represents a particular API call - how the request should be structured and how the response data should be interpreted.",
    "homepage": "https://github.com/johnpatrickmorgan/FireRoutes",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "johnpatrickmorgan": "[email protected]"
    },
    "source": {
        "git": "https://github.com/johnpatrickmorgan/FireRoutes.git",
        "tag": "0.2.4"
    },
    "social_media_url": "https://twitter.com/jpmmusic",
    "platforms": {
        "ios": "9.0"
    },
    "requires_arc": true,
    "source_files": "Source/**/*",
    "dependencies": {
        "Alamofire": [
            "~> 4.0"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This