Swiftpack.co - mihaelamj/RequestAdapter as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by mihaelamj.
mihaelamj/RequestAdapter 0.2.0
Request adapter for URL requests from "MovieLister" demo app (Swift for Good book, a chapter by Ben Scheirman)
⭐️ 0
🕓 1 week ago
.package(url: "https://github.com/mihaelamj/RequestAdapter.git", from: "0.2.0")

RequestAdapter

Request adapter for URL requests from "MovieLister" demo app (Swift for Good book, a chapter by Ben Scheirman)

The code is taken from:

Movie Lister

Usage

1. Implement the desired functionality inside the adapter protocol methods

struct UserAuthAdapter : RequestAdapter {
  func onResponse(response: URLResponse?, data: Data?) {
    if let urlResponse = response as? HTTPURLResponse {
      UserAuthData.saveToRepositoryFrom(urlResponse: urlResponse)
    }
  }
}

2. Add the adapters to your APIClient as a property

  private var adapters: [RequestAdapter]

3. Call the adapters form the implementation of the APIClient

  self.adapters.forEach { $0.beforeSend(dataRequest.request) }

or

  guard let data = data.data else {
    let error = data.error ?? AFError.explicitlyCancelled
    self.adapters.forEach { $0.onError(request: dataRequest.request, error: error) }

GitHub

link
Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics