IORequestable 0.1.6

IORequestable 0.1.6

Maintained by Roy Hu.

  • By
  • royhcj


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


Specify a shared base URL

import IORequestable
import Moya

protocol SomeIORequestable: MoyaIORequestable {}
extension SomeIORequestable {
  var baseURL: URL {
    return URL(string: "")!

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.



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

pod 'IORequestable'


royhcj, [email protected]


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