Lightweight Concurrent Networking Framework

Overview

Dots

CI Status Version License Platform

banner

Example

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

Requirements

  • iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 8.0+
  • Swift 4.0+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1+ is required to build StorageManager.

To integrate StorageManager into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Dots'
end

Then, run the following command:

$ pod install

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 StorageManager into your Xcode project using Carthage, specify it in your Cartfile:

github "iAmrSalman/Dots" ~> 0.5.0

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

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but StorageManager does support its use on supported platforms.

Once you have your Swift package set up, adding StorageManager as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/iAmrSalman/Dots.git", from: "0.5.0")
]

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.

You might also like...
Sherlock Holmes of the networking layer. :male_detective:
Sherlock Holmes of the networking layer. :male_detective:

ResponseDetective is a non-intrusive framework for intercepting any outgoing requests and incoming responses between your app and your server for debu

🌏 A zero-dependency networking solution for building modern and secure iOS, watchOS, macOS and tvOS applications.
🌏 A zero-dependency networking solution for building modern and secure iOS, watchOS, macOS and tvOS applications.

A zero-dependency networking solution for building modern and secure iOS, watchOS, macOS and tvOS applications. 🚀 TermiNetwork was tested in a produc

 Circles: E2E encrypted social networking
Circles: E2E encrypted social networking

E2E encrypted social networking built on Matrix. Safe, private sharing for your friends, family, and community.

Malibu is a networking library built on promises
Malibu is a networking library built on promises

Description Palm trees, coral reefs and breaking waves. Welcome to the surf club Malibu, a networking library built on promises. It's more than just a

Restofire is a protocol oriented networking client for Alamofire
Restofire is a protocol oriented networking client for Alamofire

Restofire is a protocol oriented networking client for Alamofire. Features Requirements Installation Usage License Features Global Configuration for h

Simple asynchronous HTTP networking class for Swift

YYHRequest YYHRequest is a simple and lightweight class for loading asynchronous HTTP requests in Swift. Built on NSURLConnection and NSOperationQueue

RSNetworking is a networking library written entirly for the Swift programming language.

RSNetworking is a networking library written entirly for the Swift programming language.

Asynchronous socket networking library for Mac and iOS

CocoaAsyncSocket CocoaAsyncSocket provides easy-to-use and powerful asynchronous socket libraries for macOS, iOS, and tvOS. The classes are described

Showcasing simple SwiftUI and networking capabilities

CovidCounts CovidCounts is powered by SwiftUI. It allows a user to view COVID related data for different U.S. States. App Purpose This app is showcasi

Owner
Amr Salman
iOS Developer & Swift enthusiast
Amr Salman
QwikHttp is a robust, yet lightweight and simple to use HTTP networking library for iOS, tvOS and watchOS

QwikHttp is a robust, yet lightweight and simple to use HTTP networking library. It allows you to customize every aspect of your http requests within a single line of code, using a Builder style syntax to keep your code super clean.

Logan Sease 2 Mar 20, 2022
A lightweight generic networking API written purely in Swift

SwiftyNetworking SwiftyNetworking library is a generic networking library writte

Zaid Rahhawi 0 Dec 24, 2021
A Swift Multiplatform Single-threaded Non-blocking Web and Networking Framework

Serverside non-blocking IO in Swift Ask questions in our Slack channel! Lightning (formerly Edge) Node Lightning is an HTTP Server and TCP Client/Serv

SkyLab 316 Oct 6, 2022
A delightful networking framework for iOS, macOS, watchOS, and tvOS.

AFNetworking is a delightful networking library for iOS, macOS, watchOS, and tvOS. It's built on top of the Foundation URL Loading System, extending t

AFNetworking 33.3k Jan 5, 2023
Elegant HTTP Networking in Swift

Alamofire is an HTTP networking library written in Swift. Features Component Libraries Requirements Migration Guides Communication Installation Usage

Alamofire 38.7k Jan 8, 2023
Type-safe networking abstraction layer that associates request type with response type.

APIKit APIKit is a type-safe networking abstraction layer that associates request type with response type. // SearchRepositoriesRequest conforms to Re

Yosuke Ishikawa 1.9k Dec 30, 2022
Robust Swift networking for web APIs

Conduit Conduit is a session-based Swift HTTP networking and auth library. Within each session, requests are sent through a serial pipeline before bei

Mindbody 52 Oct 26, 2022
Versatile HTTP Networking in Swift

Net is a versatile HTTP networking library written in Swift. ?? Features URL / JSON / Property List Parameter Encoding Upload File / Data / Stream / M

Intelygenz 124 Dec 6, 2022
A type-safe, high-level networking solution for Swift apps

What Type-safe network calls made easy Netswift offers an easy way to perform network calls in a structured and type-safe way. Why Networking in Swift

Dorian Grolaux 23 Apr 27, 2022
🏇 A Swift HTTP / HTTPS networking library just incidentally execute on machines

Thus, programs must be written for people to read, and only incidentally for machines to execute. Harold Abelson, "Structure and Interpretation of Com

John Lui 845 Oct 30, 2022