Latest 0.1.2
Homepage https://github.com/royhcj/IORequestable
License MIT
Platforms ios 9.0
Authors

CI Status
Version
License
Platform

A simple way to define and execute your web API with IORequestable in Swift.

What is it?

IORequestable provides a clean and easy way to create web APIs by encapsulating codable input and output types together with URL request specifications based on an abstraction layer of Moya.

API = Encodable Input + Decodable Output + URL and other options

Usage

Specify a shared base URL

import IORequestable
import Moya

protocol SomeIORequestable: MoyaIORequestable {}
extension SomeIORequestable {
  var baseURL: URL {
    return URL(string: "https://example.com")!
  }
}

Define an API

struct GetUserInfo: SomeIORequestable {

  var spec = Spec(.get, "/user",
                  inputEncoding: .urlParameter)

  struct Input: Encodable {
    let userID: Int
    let language: String?
  }

  struct Output: Decodable {
    let name: String
    let height: Double?
    let weight: Double?
  }

}

That’s it! You have just created an executable API. Let’s run it and give it a try.

Execute an API request

  GetUserInfo { $0.init(userID: 5, language: "en_us") }
    .execute() { result in
      switch result {
      case .success(let output):
        // ...
      case .failure(let error):
        // ...
      }
    }

Other tips

To use an existing model as Input or Output, use typealias.

struct GetUserInfo: SomeIORequestable {
  var spec = ...

  struct Input: Encodable {
    ...
  }

  typealias Output = Person // Use Person as Output,
                            // where Person conforms to Decodable.  
}

Sample Project

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

Requirements

Installation

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

pod 'IORequestable'

Author

royhcj, [email protected]

License

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

Latest podspec

{
    "name": "IORequestable",
    "version": "0.1.2",
    "summary": "A simple way to define and execute your web API with IORequestable in Swift.",
    "description": "IORequestable provides a clean and easy way to create web APIs by encapsulating codable input and output types together with URL request specifications based on an abstraction layer of Moya.",
    "homepage": "https://github.com/royhcj/IORequestable",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "royhcj": "[email protected]"
    },
    "source": {
        "git": "https://github.com/royhcj/IORequestable.git",
        "tag": "0.1.2"
    },
    "platforms": {
        "ios": "9.0"
    },
    "swift_version": "4.0",
    "default_subspecs": "Core",
    "subspecs": [
        {
            "name": "Core",
            "source_files": "IORequestable/Classes/Core/**/*",
            "dependencies": {
                "Alamofire": [],
                "Result": [],
                "Moya": [
                    "~> 12.0.0"
                ],
                "SwiftyJSON": [
                    "~> 4.2.0"
                ]
            }
        },
        {
            "name": "RxSwift",
            "source_files": "IORequestable/Classes/RxSwift/**/*",
            "dependencies": {
                "IORequestable/Core": [],
                "RxSwift": [
                    "~> 4.4.0"
                ],
                "RxCocoa": [
                    "~> 4.4.0"
                ]
            }
        }
    ]
}

Pin It on Pinterest

Share This