Latest 1.0.7
Homepage https://github.com/limadeveloper/BaseNetworkKit
License MIT
Platforms ios 9.3, requires ARC
Authors

GitHub release
Build Status
CocoaPods
GitHub repo size
License
Platform

BaseNetworkKit is the easiest way to create your network layer in Swift.
Inspired by Moya

Requirements

  • iOS 9.3+
  • Swift 4.1+

Installation

CocoaPods

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

pod 'BaseNetworkKit', '~> 1.0'

and run pod install

Manual

Just copy source folder to your project.

Framework > BaseNetworkKit > Source

How to use

Import library in your network layer:

import BaseNetworkKit

Example using Twitch API:

Setup request

enum RequesterAPI {
  case topGames(ModelRequest)
}

extension RequesterAPI: NKFlowTarget {
  var baseURL: URL {
    return URL(stringValue: "https://api.twitch.tv/")
  }

  var path: String {
    switch self {
    case .topGames:
      return "kraken/games/top"
    }
  }

  var method: NKHTTPMethods {
    return .get
  }

  var headers: NKCommon.HTTPHeader? {
    return [
      "Accept": "application/vnd.twitchtv.v5+json",
      "Client-ID": "5f1mxwqmosk9lsmwoglmz7o6icahcq"
    ]
  }

  var task: NKTask {
    switch self {
    case .topGames(let body):
      guard let params = body.dictionary(), !params.isEmpty else {
        return .requestPlain
      }
      return .requestParameters(params, encoding: .queryString)
    }
  }

  var environment: NKEnvironment {
    return .develop
  }
}

Than, create a request function

class DashService: NKBaseService<DashAPI> {
  func fetchGames(page: Int, limit: Int, completion: @escaping NKCommon.ResultType<Model>) {
    let requestModel = ModelRequest(offset: "(page)", limit: "(limit)")
    fetch(.topGames(requestModel), dataType: Model.self, completion: completion)
  }
}

If you need more examples, open demo project.

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request. 👨🏻‍💻

License

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

Latest podspec

{
    "name": "BaseNetworkKit",
    "version": "1.0.7",
    "summary": "BaseNetworkKit is the easiest way to create your network layer in Swift",
    "requires_arc": true,
    "homepage": "https://github.com/limadeveloper/BaseNetworkKit",
    "license": "MIT",
    "authors": {
        "John Lima": "[email protected]"
    },
    "social_media_url": "https://twitter.com/thejohnlima",
    "platforms": {
        "ios": "9.3"
    },
    "source": {
        "git": "https://github.com/limadeveloper/BaseNetworkKit.git",
        "tag": "1.0.7"
    },
    "source_files": "Framework/BaseNetworkKit/Source/**/*.{swift}",
    "swift_versions": "4.1",
    "swift_version": "4.1"
}

Pin It on Pinterest

Share This