A reactive library for using URLSession

Overview

NetworkService

Reactive wrapper for URLSession using Combine. At its core, the library consist of the NetworkServiceClient protocol along with a minimal implementation NetworkService.

CustomCodable

A notable convenience the library provides is the CustomCodable protocol that enables easy encoding and decoding of conforming types. The protocol associates a TopLevelEncoder and TopLevelDecoder with a given type so that it is used by the library without explicitly passing it as a parameter. Additionally, CustomEncodable and CustomDecodable are included.

Basic Usage

import NetworkService
let networkService = NetworkService()
let url = URL(string: "http://www.foobar.com")!
struct Foo: CustomCodable {
    static var encoder: JSONEncoder { JSONEncoder() }
    static var decoder: JSONDecoder { JSONDecoder() }
    let bar: Int
}
let foo = Foo(bar: 0)

GET

let publisher: AnyPublisher 
   = networkService.
   get(url)

   let cancellable 
   = publisher.
   assertNoFailure().
   sink { foo 
   in
    
   print(foo.
   bar)
}
  

POST

let publisher: AnyPublisher 
   = networkService.
   post(foo, 
   to: url)

   let cancellable 
   = publisher.
   assertNoFailure().
   sink { foo 
   in
    
   print(foo.
   bar)
}
  

PUT

let publisher: AnyPublisher 
   = networkService.
   put(foo, 
   to: url)

   let cancellable 
   = publisher.
   assertNoFailure().
   sink { foo 
   in
    
   print(foo.
   bar)
}
  

DELETE

let publisher: AnyPublisher 
   = networkService.
   get(url)

   let cancellable 
   = publisher.
   assertNoFailure().
   sink { 
   _ 
   in }
  

Start

var request = URLRequest(url: url)
request.method = .GET
let publisher: AnyPublisher 
   = networkService.
   start(request)

   let cancellable 
   = publisher.
   assertNoFailure().
   sink { foo 
   in
    
   print(foo.
   bar)
}
  

NetworkServiceTestHelper

Provides MockNetworkService which is an implementation of NetworkServiceClient for testing. Supports defining set output values for all network functions, repeating values, and delaying responses.

Installation

Currently, only Swift Package Manager is supported.

You might also like...
Plugin and runtime library for using protobuf with Swift

Swift Protobuf Welcome to Swift Protobuf! Apple's Swift programming language is a perfect complement to Google's Protocol Buffer ("protobuf") serializ

AsyncHTTP - Generic networking library written using Swift async/await

Generic networking library written using Swift async/await

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.

SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN.

SwiftCANLib SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN. Th

Publish and discover services using Bonjour

Ciao Lib to publish and find services using mDNS Requirements Installation Usage License Requirements iOS 8.0+ / Mac OS X 10.10+ / tvOS 9.0+ Xcode 9.0

Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux.

BlueSocket Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux. Prerequisites Swift Swift Open Source swift-5.1

Swift HTTP server using the pre-fork worker model

Curassow Curassow is a Swift Nest HTTP Server. It uses the pre-fork worker model and it's similar to Python's Gunicorn and Ruby's Unicorn. It exposes

SSL/TLS Add-in for BlueSocket using Secure Transport and OpenSSL

BlueSSLService SSL/TLS Add-in framework for BlueSocket in Swift using the Swift Package Manager. Works on supported Apple platforms (using Secure Tran

 Postie - The Next-Level HTTP API Client using Combine
Postie - The Next-Level HTTP API Client using Combine

Postie - The Next-Level HTTP API Client using Combine Postie is a pure Swift library for building URLRequests using property wrappers.

Comments
  • Add .swiftpm to gitignore to stop schemes from polluting packages that depend on NetworkService

    Add .swiftpm to gitignore to stop schemes from polluting packages that depend on NetworkService

    • Add .swiftpm to gitignore to stop schemes from polluting packages that depend on NetworkService
    • Run swiftformat
    • Update ci.yml to use newer codecov flow
    • Add codecov badge to README
    • Remove unnecessary use of try!. Resolves issue https://github.com/MFB-Technologies-Inc/NetworkService/issues/1.
    • Add missing assertion descriptions in tests. Resolves swiftlint warnings.

    feature/stop-schemes-from-polluting-dependents

    opened by roanutil 1
  • Unnecessary `try!` in `MockOutput` conformances

    Unnecessary `try!` in `MockOutput` conformances

    https://github.com/MFB-Technologies-Inc/NetworkService/blob/026a453bdc65b3c4c1aec0ef3ac330c05ebeb619/Sources/NetworkServiceTestHelper/MockNetworkService.swift#L133

    https://github.com/MFB-Technologies-Inc/NetworkService/blob/026a453bdc65b3c4c1aec0ef3ac330c05ebeb619/Sources/NetworkServiceTestHelper/MockNetworkService.swift#L153

    opened by roanutil 1
  • Feature/structured concurrency

    Feature/structured concurrency

    Add standalone targets that upgrade all code to use async/await instead of Combine. A future PR/release will remove the old Combine based targets and make the async/await targets main.

    opened by roanutil 0
Releases(2.1.2)
  • 2.1.2(Nov 15, 2022)

    What's Changed

    • Add .swiftpm to gitignore to stop schemes from polluting packages that depend on NetworkService by @roanutil in https://github.com/MFB-Technologies-Inc/NetworkService/pull/5
    • Run swiftformat by @roanutil in https://github.com/MFB-Technologies-Inc/NetworkService/pull/5
    • Update ci.yml to use newer codecov flow by @roanutil in https://github.com/MFB-Technologies-Inc/NetworkService/pull/5
    • Add codecov badge to README by @roanutil in https://github.com/MFB-Technologies-Inc/NetworkService/pull/5
    • Remove unnecessary use of try!. Resolves issue https://github.com/MFB-Technologies-Inc/NetworkService/issues/1. by @roanutil in https://github.com/MFB-Technologies-Inc/NetworkService/pull/5
    • Add missing assertion descriptions in tests. Resolves swiftlint warnings. by @roanutil in https://github.com/MFB-Technologies-Inc/NetworkService/pull/5

    Full Changelog: https://github.com/MFB-Technologies-Inc/NetworkService/compare/2.1.1...2.1.2

    Source code(tar.gz)
    Source code(zip)
  • 2.1.1(Sep 20, 2022)

    What's Changed

    • Remove unsafe swift flags by @roanutil in https://github.com/MFB-Technologies-Inc/NetworkService/pull/4

    Full Changelog: https://github.com/MFB-Technologies-Inc/NetworkService/compare/2.1.0...2.1.1

    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Sep 20, 2022)

    What's Changed

    • Feature/structured concurrency by @roanutil in https://github.com/MFB-Technologies-Inc/NetworkService/pull/3

    Full Changelog: https://github.com/MFB-Technologies-Inc/NetworkService/compare/2.0.0...2.1.0

    Source code(tar.gz)
    Source code(zip)
Owner
MFB Technologies, Inc.
MFB Technologies, Inc.
Write clean, concise and declarative network code relying on URLSession, with the power of RxSwift. Inspired by Retrofit.

ReactiveAPI Reactive API library allows you to write clean, concise and declarative network code, with the power of RxSwift and URLSession! iOS Demo A

Sky UK Ltd 79 Nov 19, 2022
To practice URLSession to fetch json data from open weather API

⛅️ weatherApp-iOS-practice ?? 기능 상세 도시 이름을 입력하면 현재 날씨 정보를 가져와 화면에 표시되게 만들어야 합니다

Jacob Ko 0 Dec 18, 2021
GeminiProtocol - URLSession support for the Gemini Protocol

GeminiProtocol Network.Framework and URLSession support for the Gemini Protocol

Izzy 3 Feb 16, 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
Reactive WebSockets

RxWebSocket Reactive extensions for websockets. A lightweight abstraction layer over Starscream to make it reactive. Installation RxWebSocket is avail

Flávio Caetano 57 Jul 22, 2022
Declarative and Reactive Networking for Swift.

Squid Squid is a declarative and reactive networking library for Swift. Developed for Swift 5, it aims to make use of the latest language features. Th

Oliver Borchert 69 Dec 18, 2022
Swift-flows - Simplistic hot and cold flow-based reactive observer pattern for Swift… ideal for MVVM architectures

SwiftFlows Simplistic hot and cold flow-based reactive observer pattern for Swif

Tyler Suehr 0 Feb 2, 2022
Simple iOS app in Swift to show AQI for some cities using websocket using Combine + MVVM

AQI Simple iOS app in Swift to show AQI for some cities using websocket using Combine + MVVM This app follows MVVM This app uses combine framework The

Amey Vikkram Tiwari 2 Nov 6, 2022
WebSocket(RFC-6455) library written using Swift

DNWebSocket Object-Oriented, Swift-style WebSocket Library (RFC 6455) for Swift-compatible Platforms. Tests Installation Requirements Usage Tests Conf

Gleb Radchenko 36 Jan 29, 2022
An awesome Swift HTML DSL library using result builders.

SwiftHtml An awesome Swift HTML DSL library using result builders. let doc = Document(.html5) { Html { Head { Meta()

Binary Birds 204 Dec 25, 2022