Skip to content
This repository has been archived by the owner on Jul 2, 2020. It is now read-only.
/ Springbok Public archive

A light and fast HTTP Networking in Swift

Notifications You must be signed in to change notification settings

ml-archive/Springbok

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Springbok

dependencies Status Carthage Compatible Language Xcode

📖 Project description

Springbok is a light and fast HTTP Networking in Swift working with Codable.

📂 Features

  • Chainable Request / Response Methods
  • Request handle is background and Response in the main thread
  • Works with Codable !
  • UIImageView extension to set image
  • UIImage set in cache (only memory for now)

🔧 Installation

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Springbok into your Xcode project using Carthage, specify it in your Cartfile:

github "nodes-ios/Springbok"

Run carthage update to build the framework and drag the built Springbok.framework into your Xcode project.

📝 Documentation

Define your Model

struct User: Codable {
    let id: Int
    let name: String
    ...
}

Making simple request

import Springbok

    Springbok
        .request("<your_url>")
        .responseCodable { (result: Result<User>) in
            switch result {
            case .success(let user):
                // request successful, your model is decoded !
            case .failure(let error):
                // request failed ...
            }
        }

Making elaborated request

import Springbok

    Springbok
        .request(
            "<your_url>", 
            method: .post, // .get, .post, .patch, .put, .delete
            parameters: ["id": 1], // [String: Any]
            headers: ["Content-Type": "application/json"] // [String: String]
        )
        .responseCodable { (result: Result<User>) in
            switch result {
            case .success(let playlists):
                // request successful, your model is decoded !
            case .failure(let error):
                // request failed ...
            }
        }

Unwrap your data

If your server returns data like this :

{
   "<root_object_name>": [
      {
         "id": 1,
         "name": "John Doe"
      },
      ...
   ]
}

You need to unwrap the response in order to decode it.

import Springbok

Springbok
        .request("<your_url>")
        .unwrap("root_object_name") // the name of your root object
        .responseCodable { (result: Result<User>) in
            switch result {
            case .success(let user):
                // request successful, your model is decoded !
            case .failure(let error):
                // request failed ...
            }
        }

Download images

You can download images and set into imageView like :

import Springbok

// without option (by default fading animation is true, duration is 0.3 and placeholder image is nil)
imageView.setImage(url: "<your_url>")

// With options
imageView.setImage(url: "", fading: true, duration: 0.5, placeholderImage: nil)

You can also cancel download image task by doing :

import Springbok

imageView.cancelDownloadTask()

Cancel requets

You can cancel request with the given url :

import Springbok

Springbok.cancelRequest(url: "<your_url>")

💻 Developers