Async network layer with Combine

Overview

Version 1.0.10

apmCocoaPods compatible Carthage compatible Swift Package Manager compatible Swift

Currently Available

Platform Version
iOS 12.0
tvOS 10.0
macOS 10.15
watchOS 3.0
macCatalyst 13.0

Hover is a Network layer which uses Apple's new framework Combine and provides async network calls with different kind of request functions.

Why and When to Use

The main benefit to use Hover is to abstract the networking layer as much as possible and remove redunant code from your projects as we know Apple announced a new framework called Combine the main goal is to provide a declarative Swift API for processing values over time. These values can represent many kinds of asynchronous events, so networking calls are the most important async events, which actually needs to have a support for Combine to prevent and integrate Apple's native framework. Why you shouldnt use is when you dont have that much networking calls and also not so complex data flows to keep track on which means actually that you dont have states for the UI then dont use it. :)

Cocoapods Installation

target 'MyApp' do
  pod 'HoverKitSDK', "~> 1.0.10"
end

Carthage Installation

github "onurhuseyincantay/Hover" ~> 1.0.10

if you are using Xcode 12 there are additional steps to take:

  1. create a carthage.sh file
  2. add the following code
set -euo pipefail

xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX)
trap 'rm -f "$xcconfig"' INT TERM HUP EXIT

# For Xcode 12 (beta 3+) make sure EXCLUDED_ARCHS is set to arm architectures otherwise
# the build will fail on lipo due to duplicate architectures.
echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200 = arm64 arm64e armv7 armv7s armv6 armv8' >> $xcconfig
echo 'EXCLUDED_ARCHS = $(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT)__XCODE_$(XCODE_VERSION_MAJOR))' >> $xcconfig

export XCODE_XCCONFIG_FILE="$xcconfig"
carthage build "$@"

  1. use chmod +x carthage.sh to make it executable
  2. rather than running carthage run ./carthage.sh { any carthage command you need }

Swift Package Manager Installation

Package branch

Sample Usage

Provide Target

 enum UserTarget {
  case login(email: String, password: String) 
 }
 
 extension UserTarget: NetworkTarget { 
    var path: String {
        switch self {
        ...
    }
    var providerType: AuthProviderType {
        ...
    }
    
    var baseURL: URL {
        ...
    }
    
    var methodType: MethodType {
        switch self {
          ...
        }
    }
    
    var contentType: ContentType? {
        switch self {
         ...
        }
    }
    
    var workType: WorkType {
        switch self {
          ...
        }
    }
    
    var headers: [String : String]? {
        ...
    }
 }

Request With Publisher

let provider = Hover()
let publisher = provider.request(
            with: UserTarget.login(email: "[email protected]", password: "123456"),
            scheduler: DispatchQueue.main,
            class: UserModel.self
        )
...
publisher.sink({ ... })

Request With Subscriber

let provider = Hover()
let userSubscriber = UserSubscriber()
provider.request(with: UserTarget.login(email: "[email protected]", password: "123456"), class: UserModel.self, subscriber: userSubscriber)

Tested with JsonPlaceholder Inspired By Moya Developed with 🧡

You might also like...
Generic Network Layer created using Swift.

Generic-Network-Layer_iOS Generic Network Layer created using URLSession. Networking is an essential element in app development, and you'll need API c

NSURLSession network abstraction layer, using Codable and Decodable for response and Encodable for request. ⚙️🚀
NSURLSession network abstraction layer, using Codable and Decodable for response and Encodable for request. ⚙️🚀

SONetworking NSURLSession network abstraction layer, using Codable and Decodable for response and Encodable for request. Project Folder and File Struc

Alamofire network layer

NVNetworkRequest Alamofire network layer Installation Add this to your Package dependencies: dependencies: [ .package(url: "https://github.com/vin

Network abstraction layer written in Swift.
Network abstraction layer written in Swift.

Moya 15.0.0 A Chinese version of this document can be found here. You're a smart developer. You probably use Alamofire to abstract away access to URLS

VFNetwork is a protocol-oriented network layer that will help you assemble your requests in just a few steps.
VFNetwork is a protocol-oriented network layer that will help you assemble your requests in just a few steps.

Simple, Fast and Easy. Introduction VFNetwork is a protocol-oriented network layer that will help you assemble your requests in just a few steps. How

A network extension app to block a user input URI. Meant as a network extension filter proof of concept.
A network extension app to block a user input URI. Meant as a network extension filter proof of concept.

URIBlockNE A network extension app to block a user input URI. Meant as a network extension filter proof of concept. This is just a research effort to

NWReachability - a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

NWReachability is a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

A Combine-style wrapper around Network's NWConnection with a UDP protocol

A Combine-style wrapper around Network's NWConnection with a UDP protocol

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

Comments
  • WorkType L15  Encodable issue

    WorkType L15 Encodable issue

    https://github.com/onurhuseyincantay/Hover/blob/master/Sources/Hover/Types/WorkType.swift#L15

    I think it bugs. this is how I fixed

    public struct AnyEncodable: Encodable {
        public let encodable: Encodable
    
        public init(_ encodable: Encodable) {
            self.encodable = encodable
        }
    
        public func encode(to encoder: Encoder) throws {
            try self.encodable.encode(to: encoder)
        }
    }
    
    public enum DataType {
        case requestPlain
        case requestData(data: Data)
        case requestParameters(parameters: [String: Any], encoding: JSONEncoder = JSONEncoder())
        case requestWithEncodable(encodable: AnyEncodable)
    }
    
    bug question 
    opened by saroar 5
  • Request is cancelled on Mac Catalyst

    Request is cancelled on Mac Catalyst

    Here's the response:

     Task <31B06E42-1D6F-42C2-84A8-65CB0BEE175F>.<1> finished with error [-999] Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://api.notemate.com/notemate/register, NSLocalizedDescription=cancelled, NSErrorFailingURLKey=https://api.notemate.com/notemate/register}
    
    bug 
    opened by anonrig 1
  • Make CI & CD Pass

    Make CI & CD Pass

    Currently the swift batch is not passing the update the failing tests and make it pass again it might be because of the JsonPlaceholderAPI that we are using as test resource.

    bug 
    opened by onurhuseyincantay 0
  • Debug Logging Support

    Debug Logging Support

    Adding Shared Preference where you can enable disable debugging option and will show endpoint path header attributes and body response or error if neede.

    enhancement 
    opened by onurhuseyincantay 0
Releases(1.0.10)
Owner
Onur Hüseyin Çantay
Excited about Swift, Objective-C and a good follower of  Apple Technology Playing also a bit with Golang.
Onur Hüseyin Çantay
Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application.

Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application. Install Carthage

Ronan Rodrigo Nunes 89 Dec 26, 2022
Say goodbye to the Fat ugly singleton Network Manager with this Network Layer

MHNetwork Protocol Oriented Network Layer Aim to avoid having bloated singleton NetworkManager Philosophy the main philosophy behind MHNetwork is to h

Mohamed Emad Hegab 19 Nov 19, 2022
Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Igor 2 Sep 16, 2022
Alamofire Network Layer written in swift 5 using the protocol oriented, combine, UIKit, MVVM.

CoreAPI-iOS This project Contains Alamofire Network layer Based on Protocol Oriented Concept and Combine Framework. It is created with UIKit, Alamofir

Mehran Kamalifard 27 Nov 11, 2022
🤵🏽‍♀️ Janet — A thin HTTP networking layer built on URLSession for simple, declarative endpoint specification leveraging the power of async/await.

????‍♀️ Janet — Just another networking kit — A thin HTTP networking layer built on URLSession for simple, declarative endpoint specification leveragi

Niklas Holloh 3 Sep 6, 2022
Dratini is a neat network abstraction layer.

Dratini Dratini is a neat network abstraction layer. If you are looking for a solution to make your network layer neat, Dratini is your choice. Dratin

Kevin Lin 37 Jan 29, 2022
Network abstraction layer written in Swift.

Moya 14.0.0 A Chinese version of this document can be found here. You're a smart developer. You probably use Alamofire to abstract away access to URLS

Moya 14.4k Jan 1, 2023
Elegant network abstraction layer in Swift.

Elegant network abstraction layer in Swift. 中文 Design Features Requirements Communication Installation Usage Base Usage - Target - Request - Download

null 100 Dec 9, 2022
Lightweight network abstraction layer, written on top of Alamofire

TRON is a lightweight network abstraction layer, built on top of Alamofire. It can be used to dramatically simplify interacting with RESTful JSON web-

MLSDev 528 Dec 26, 2022
A generic network layer written in swift

SwiftyNet 1.0.0 A generic network layer written in swift. you can use it as an abstraction layer above Alamofire with generic returned types. Installa

Mohamed Salah Zidane 17 Oct 11, 2021