Latest 0.4.1
Homepage https://github.com/iAmrSalman/Dots
License MIT
Platforms ios 10.0
Frameworks UIKit
Authors

CI Status
Version
License
Platform
Swift 3.1 compatible

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 10.0+
  • Xcode 8.0+
  • Swift 3.0+

Installation

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

pod "Dots"

Usage

Making a Request

import Dots

Dots.defualt.request("<URL>") { (dot: Dot) in

  print(dot.response) // HTTP URL response
  print(dot.data)     // server data
  print(dot.error)    // Errors from request processing
  print(dot.json)     // JSON dictionary [String: Any]

}

HTTP Methods

The HTTPMethod enumeration lists the HTTP methods:

public enum HTTPMethod: String {
case options = "OPTIONS"
case get     = "GET"
case head    = "HEAD"
case post    = "POST"
case put     = "PUT"
case patch   = "PATCH"
case delete  = "DELETE"
case trace   = "TRACE"
case connect = "CONNECT"
}

These values can be passed as the method argument to the request Function:

Dots.defualt.request("<URL>") // method defaults to `.get`
Dots.defualt.request("<URL>", method: .post)
Dots.defualt.request("<URL>", method: .put)
Dots.defualt.request("<URL>", method: .delete)

The request method parameter defaults to .get.

Parameter Encoding

GET Request With URL-Encoded Parameters

let parameters: Parameters = ["foo": "bar"]

Dots.defualt.request("<URL>", parameters: parameters) // defaults url encoding
Dots.defualt.request("<URL>", parameters: parameters, encoding: .url)

// <URL>?foo=bar

POST Request With URL-Encoded Parameters

let parameters: Parameters = [
  "foo": "bar",
  "baz": ["a", 1],
  "qux": [
    "x": 1,
    "y": 2,
    "z": 3
  ]
]

Dots.defualt.request("<URL>", method: .post, parameters: parameters) // defaults url encoding
Dots.defualt.request("<URL>", method: .post, parameters: parameters, encoding: .url)

//httpHeader: Content-Type: application/x-www-form-urlencoded; charset=utf-8

// HTTP body: foo=bar&baz[]=a&baz[]=1&qux[x]=1&qux[y]=2&qux[z]=3

POST Request With JSON-Encoded Parameters

let parameters: Parameters = [
  "foo": [1,2,3],
  "bar": [
    "baz": "qux"
  ]
]

Dots.defualt.request("<URL>", method: .post, parameters: parameters, encoding: .json)

//HTTP header: Content-Type: application/json

// HTTP body: {"foo": [1, 2, 3], "bar": {"baz": "qux"}}

HTTP Headers

Adding a custom HTTP header to a Request is supported directly in the global request method. This makes it easy to attach HTTP headers to a Request.

let headers: HTTPHeaders = [
  "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
  "Accept": "application/json"
]

Dots.defualt.request("<URL>", headers: headers)

Concurrency

Choosing between Asynchronous and Synchronous is supported


Dots.defualt.request("<URL>", concurrency: .async) // concurrency defaults to `.async`
Dots.defualt.request("<URL>", concurrency: .sync)

Maximum concurrent requests

Customizing Maximum concurrent requests executing simultaneously is supported.

The defualt is checking if device is on cellular connection, maximum concurrent requests is restricted to 2, while Wi-Fi is executing up to 6 simultaneous requests.


let customDots = Dots(maxConcurrentOperation: <Int>)

customDots.request("<URL>") 

Extensions

UIImageView

imageView.setImage(withURL: "<URL>")

Author

Amr Salman, [email protected]

License

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

Latest podspec

{
    "name": "Dots",
    "version": "0.4.1",
    "summary": "Lightweight iOS Concurrent Networking Framework.",
    "description": "Lightweight iOS Concurrent Networking Framework that will make developing your Apps easire and faster",
    "homepage": "https://github.com/iAmrSalman/Dots",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Amr Salman": "[email protected]"
    },
    "source": {
        "git": "https://github.com/iAmrSalman/Dots.git",
        "tag": "0.4.1"
    },
    "social_media_url": "https://twitter.com/@iAmrSalman",
    "platforms": {
        "ios": "10.0"
    },
    "source_files": "Dots/Classes/**/*",
    "frameworks": "UIKit",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This