All Projects → ThreeGayHub → Solarnetwork

ThreeGayHub / Solarnetwork

Licence: mit
Elegant network abstraction layer in Swift.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Solarnetwork

Dratini
Dratini is a neat network abstraction layer.
Stars: ✭ 38 (-61.62%)
Mutual labels:  network, networking
Netfil
A kernel network manager with monitoring and limiting capabilities for macOS. #nsacyber
Stars: ✭ 97 (-2.02%)
Mutual labels:  network, networking
Ineter
Fast Java library for working with IP addresses, ranges, and subnets
Stars: ✭ 39 (-60.61%)
Mutual labels:  network, networking
Bash Toolkit
Este proyecto esá destinado a ayudar a los sysadmin
Stars: ✭ 13 (-86.87%)
Mutual labels:  network, networking
Pynms
A vendor-agnostic NMS for carrier-grade network simulation and automation
Stars: ✭ 73 (-26.26%)
Mutual labels:  network, networking
Libzmq
ZeroMQ core engine in C++, implements ZMTP/3.1
Stars: ✭ 7,418 (+7392.93%)
Mutual labels:  network, networking
Pnet
High level Java network library
Stars: ✭ 49 (-50.51%)
Mutual labels:  network, networking
P2p
Practice project to demonstrate p2p file sharing.
Stars: ✭ 16 (-83.84%)
Mutual labels:  network, networking
Avenue
Wrapper around URLSession and URLSessionTask to enable seamless integration with Operation / OperationQueue.
Stars: ✭ 58 (-41.41%)
Mutual labels:  network, networking
Macfinder
An iOS Library that helps you find the MAC Address of a specific IP
Stars: ✭ 57 (-42.42%)
Mutual labels:  network, networking
Metta
An information security preparedness tool to do adversarial simulation.
Stars: ✭ 867 (+775.76%)
Mutual labels:  network, networking
Stnettaskqueue
STNetTaskQueue is a networking queue library for iOS and OS X. It's abstract and can be implemented in different protocols.
Stars: ✭ 90 (-9.09%)
Mutual labels:  network, networking
Librg
🚀 Making multi-player gamedev simpler since 2017
Stars: ✭ 813 (+721.21%)
Mutual labels:  network, networking
Xdp
Package xdp allows one to use XDP sockets from the Go programming language.
Stars: ✭ 36 (-63.64%)
Mutual labels:  network, networking
Diffios
Cisco IOS diff tool
Stars: ✭ 23 (-76.77%)
Mutual labels:  network, networking
Dknetworking
基于 AFNetworking + YYCache 的二次封装,支持缓存策略的网络请求框架
Stars: ✭ 41 (-58.59%)
Mutual labels:  network, networking
Bmon
bandwidth monitor and rate estimator
Stars: ✭ 787 (+694.95%)
Mutual labels:  network, networking
Nexer
Content based network multiplexer or redirector made with love and Go
Stars: ✭ 7 (-92.93%)
Mutual labels:  network, networking
React Native Netinfo
React Native Network Info API for Android & iOS
Stars: ✭ 1,049 (+959.6%)
Mutual labels:  network, networking
Networking
Easy HTTP Networking in Swift a NSURLSession wrapper with image caching support
Stars: ✭ 1,269 (+1181.82%)
Mutual labels:  networking, alamofire

SLNetwork

CocoaPods Compatible Carthage Compatible Platform

Elegant network abstraction layer in Swift.


Design

Alamofire and Moya are elegant Swift network frames. They each have their own advantages. When I use them, I always want to combine the advantages of both, make them easy to use and retain their original features. So I wrote the SolarNetwork.

  • SLNetwork corresponds to a SessionManager.
  • SLTarget corresponds to a Host, or a set of requests for the same configuration.
  • SLRequest, SLDownloadRequest, SLUploadRequest corresponds to Request of Data, Download, Upload.
  • SLProgress return progress when download or upload.
  • SLResponse response of a request which you can decode to JsonObject or Model.
  • SLPlugin you can modify SLRequest in willSend and modify SLResponse in didReceive.
  • SLReflection reflex properties of SubSLRequest to Alamofire.Parameters.

So a complete request process is:

SLNetwork(SLTarget).request(SLRequest).willSend(SLRequest)
                   .progressClosure(SLProgress)
                   .reponseData(OriginalResponse)
                   .didReceive(SLResponse).decodeTo(Dictionary)
                   .completionClosure(SLResponse)
                   .decodeTo(Model: Decodable).dealWithError

In most cases, what you need to concerned about is:

SLNetwork(SLTarget).request(SLRequest)
                   .progressClosure(SLProgress)
                   .completionClosure(SLResponse)

Features

  • [x] URL / JSON / plist Parameter Encoding
  • [x] Upload File / Data / Stream / MultipartFormData
  • [x] Download File using Request or Resume Data
  • [x] Authentication with URLCredential
  • [x] Upload and Download Progress Closures with Progress
  • [x] Dynamically Adapt and Retry Requests
  • [x] TLS Certificate and Public Key Pinning
  • [x] Network Reachability
  • [x] Pre-populate the DNS cache
  • [x] Complete Logger

Requirements

  • iOS 8.0+
  • Xcode 9+
  • Swift 4+

Communication

  • If you'd like to ask a general question, use Stack Overflow.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

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 integrate SolarNetwork into your Xcode project using CocoaPods, specify it in your Podfile:

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

target '<Your Target Name>' do
    pod 'SolarNetwork'
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 Alamofire into your Xcode project using Carthage, specify it in your Cartfile:

github "ThreeGayHub/SolarNetwork"

Run carthage update

If this is your first time using Carthage in the project, you'll need to go through some additional steps as explained over at Carthage.


Usage

Base Usage

Target

import SolarNetwork

struct HTTPBinTarget: SLTarget {
    var baseURLString: String { return "https://httpbin.org" }
}

let HTTPBinNetwork = SLNetwork(HTTPBinTarget())

Request

import SolarNetwork

//Mark: - GET
class HTTPBinGETRequest: SLRequest {
    
    override func loadRequest() {
        super.loadRequest()
        
        self.path = "/get"
    }
    
}

HTTPBinNetwork.request(HTTPBinGETRequest()) { (response) in
    if let dictionary = response.dataDictionary {
                        
    }
    else if let error = response.error {
        //show error
    }
}

//Mark: - POST
class HTTPBinPOSTRequest: SLRequest {
    
    override func loadRequest() {
        super.loadRequest()
        
        self.method = .post
        self.path = "/post"
    }
    
    /**
     properties will encode to parameters by Reflection
     ["userName": "myUserName",
      "password": "myPassword",
	  "name" : "youName"]
     */
    let userName = "myUserName"
    let password = "myPassword"
	
    var name: String?
}

let postReq = HTTPBinPOSTRequest()
postReq.name = "yourName"
HTTPBinNetwork.request(postReq) { (response) in
    if let dictionary = response.dataDictionary {
                        
    }
    else if let error = response.error {
        //show error
    }
}

Download

import SolarNetwork

class HTTPBinDownLoadRequest: SLDownloadRequest {
    
    override func loadRequest() {
        super.loadRequest()
        
        self.path = "/image/png"
        self.isResume = true //control the download request is resume or not, default is false
    }
}

HTTPBinNetwork.download(HTTPBinDownLoadRequest(), progressClosure: { (progress) in
                    
}) { (resposne) in
                    
}

Upload

import SolarNetwork

class HTTPBinUploadRequest: SLUploadRequest {
    
    override func loadRequest() {
        super.loadRequest()
        
        self.path = "/post"
    }
    
}

let uploadRequest = HTTPBinUploadRequest()
uploadRequest.data = data //data to upload
HTTPBinNetwork.upload(uploadRequest, progressClosure: { (progress) in
                            
}) { (response) in
                            
}

Decode

In Swift 4, you can use Codable.

import SolarNetwork

struct User: Decodable { //Swift 4 Codable
    var id: Int
    var name: String
    var token: String
}

HTTPBinNetwork.request(UserRequest()) { (response) in
    if let user = response.decode(to: User.self) {
                        
    }
    else if let error = response.error {
        //show error
    }
}

License

Alamofire is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].