Latest 0.5.1
Homepage https://github.com/hooliooo/Astral
License MIT
Platforms ios 10.0
Dependencies BrightFutures
Frameworks Foundation
Authors

CI Status
Version
License
Platform

Example Project

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

Requirements

Astral requires iOS 10.0 or higher and Swift 3.x

Installation

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

pod "Astral"

Example

Here’s an example using the Pokemon API

struct PokeAPIConfiguration: Configuration {

    var scheme: URLScheme {
        return URLScheme.http
    }

    var host: String {
        return "pokeapi.co"
    }

    var basePathComponents: [String] {
        return [
            "api",
            "v2"
        ]
    }

    var baseHeaders: [String : Any] {
        return [
            "Content-Type": "application/json"
        ]
    }
}
struct PokemonRequest: Request {

    let id: Int

    var configuration: Configuration {
        return PokeAPIConfiguration()
    }

    var pathComponents: [String] {
        return [    
            "pokemon",
            "(self.id)"
        ]
    }

    var method: HTTPMethod {
        return HTTPMethod.GET
    }

    var parameters: [String : Any] {
        return [:]
    }

    var headers: [String : Any] {
        return [:]
    }
}
let queue: DispatchQueue = DispatchQueue(label: "pokeapi", qos: DispatchQoS.userInitiated, attributes: [DispatchQueue.Attributes.concurrent])

let request: Request = PokemonRequest(id: 1)
let sender: RequestSender = JSONRequestSender<JSONRequestBuilder>(request: request, printsResponse: true)

sender.sendURLRequest()
    .onSuccess(queue.context) { (data: Data) -> Void in
        // Create and parse JSON
    }
    .onFailure(queue.context) { (error: NetworkingError) -> Void in
        // Handle the error
    }
    .onComplete(queue.context) { (result: Result<Data, NetworkingError>) -> Void in
        // Handle the completion of the network request
        // such as clean up of the UI
    }

Author

Julio Alorro

License

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

Latest podspec

{
    "name": "Astral",
    "module_name": "Astral",
    "version": "0.5.1",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "summary": "An HTTP networking library that uses protocols and Futures",
    "homepage": "https://github.com/hooliooo/Astral",
    "authors": {
        "Julio Alorro": "[email protected]"
    },
    "source": {
        "git": "https://github.com/hooliooo/Astral.git",
        "tag": "0.5.1"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source_files": "Source/**/*.swift",
    "frameworks": "Foundation",
    "dependencies": {
        "BrightFutures": []
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This