Skip to content

Networking 3 Transition Guide

Elvis Nuñez edited this page Jan 29, 2017 · 19 revisions

Introduction

Hi, and welcome to the third major release of Networking. Jumping from 0.x.x to 1.0.0 was a matter of how mature the project was, before jumping to 1.0.0 the library was tested in 3 big production apps, received a lot of input from the developers and was ready to receive input from the world. Among other things, the jump to 1.0.0 brought a lot of attention, especially from iOSDevWeekly and CocoaControls.

The jump to 2.0.0 was mainly the conversion of the whole codebase to Swift 3. The jump was easy, mainly since a lot of the core APIs were left as untouched as possible to ease the jump to Swift 3, this of course meant that some parts of Networking didn't feel very swifty. After 3 months of 2.0.0 we have refined Networking, refactored the internals, improved the unit tests and now we're ready to delete all the deprecated methods and make the big jump to 3.0.0.

Things that you need to change in order to use Networking 3.

Authentication

We have changed the authentication methods to be easier to understand and to increase readability.

Basic Auth

Before

let networking = Networking(baseURL: baseURL)
networking.authenticate(username: "user", password: "passwd")

After

Bearer Token

Before

let networking = Networking(baseURL: baseURL)
networking.authenticate(token: "hi-mom")

After

Custom Authorization Header

Before

let networking = Networking(baseURL: baseURL)
networking.authenticate(headerValue: "hi-mom")
let networking = Networking(baseURL: baseURL)
networking.authenticate(headerKey: "Anonymous-Token", headerValue: "hi-mom")

After

Method calls

Before

networking.GET(...) { ...
networking.POST(...) { ..
networking.PUT(...) { ...
networking.DELETE(...) { ...
After
networking.get(...) { ...
networking.post(...) { ..
networking.put(...) { ...
networking.delete(...) { ...

Synchronous methods

Before

networking.imageFromCache("/imagepath") { image in
}
networking.dataFromCache("/videopath") { data in
}
networking.cancelAllRequests {
    // Finished cancelling all requests
}
networking.cancelGET("/get") {
    // Finished cancelling GET "/get"  requests
}

networking.cancelPOST("/post") {
    // Finished cancelling GET "/post"  requests
}

networking.cancelPUT("/put") {
    // Finished cancelling PUT "/put"  requests
}

networking.cancelDELETE("/delete") {
    // Finished cancelling DELETE "/delete"  requests
}

After

let image = networking.imageFromCache()
let data = networking.dataFromCache("/videopath")
networking.cancelAllRequests()
networking.cancelGET("/get")
networking.cancelPOST("/post")
networking.cancelPUT("/put")
networking.cancelDELETE("/delete")

The Result type

Clone this wiki locally