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

Astral is a minimal HTTP Networking library that aims to simplify an application’s networking layer by abstracting
the steps needed to create a network request into multiple objects.

It aims to shy away from the typical network layer singleton by encapsulating each part of network request as an object.

Astral makes use of the BrightFutures library to flatten the asynchronous calls
associated with networking, making your code base as readable as possible.

Inspired by Soroush Khanlou’s blog post on Protocol Oriented
Programming.

CI Status
Version
License
Platform

Requirements

Astral requires iOS 10.0 or higher and Swift 3.x

Installation

CocoaPods

  1. Add the following to your Podfile:
pod 'Astral'
  1. Integrate your dependencies using frameworks: add use_frameworks! to your Podfile.
  2. Run pod install.

Example

Here’s an example using the Pokemon API and the implementations of RequestBuilder and RequestDispatcher
provided by Astral.

Feel free to build and customize your own implementations. Simply adopt the appropriate protocols.

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 dispatcher: RequestDispatcher = JSONRequestDispatcher(
    request: request, builderType: JSONRequestBuilder.self, printsResponse: true
)

dispatcher.dispatchURLRequest()
    .onSuccess(queue.context) { (response: Response) -> Void in
        // let responseData: Data = response.data
        // Do something with data
        // or
        // let dictionary: [String: Any] = response.json.dictValue
        // Do something with dictionary
    }
    .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.7.5",
    "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.7.5"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source_files": "Sources/**/*.swift",
    "requires_arc": true,
    "frameworks": "Foundation",
    "dependencies": {
        "BrightFutures": []
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This