Use this package in order to ease up working with Combine URLSession.

Overview

CombineURLSession

Use this package in order to ease up working with Combine URLSession. We support working with Codable for all main HTTP methods GET, POST, PUT and DELETE. We also support MultipartUpload

Instalation

To install this package just add the follwing in yor package

.package(url: "https://github.com/DanielMandea/url-session-combine.git", from: "1.0.0"),

Usage

Define SomeService Example

AnyPublisher { Publishers.CombineLatest(just(path: path), sessionProvider.jwt()).flatMap { self.get(from: $0, headers: self.merge(jwt: $1, with: headers), decoder: decoder) }.eraseToAnyPublisher() } } ">
class SomeService: BaseService {
    
    // MARK: - Session
    
    let sessionProvider: SessionProvider
    
    // MARK: - Init
    
    init(api: API = ServiceConfiguration.api, sessionProvider: SessionProvider = DefaultSessionProvider(authenticatorProvider: Authenticator())) {
        self.sessionProvider = sessionProvider
        super.init(api: api)
    }
    
    func get<T: Codable>(for path: String, headers: [String: String] = ["Content-Type":"application/json"], decoder: JSONDecoder = JSONDecoder.iso8601JsonDecoder) -> AnyPublisher
    Error> {
        Publishers.
    CombineLatest(
    just(
    path: path), sessionProvider.
    jwt()).
    flatMap {
            
    self.
    get(
    from: 
    $0, 
    headers: 
    self.
    merge(
    jwt: 
    $1, 
    with: headers), 
    decoder: decoder)
        }.
    eraseToAnyPublisher()
    }
}
   

Call SomeService Example

    get(for: "somepath/", decoder: JSONDecoder.iso8601FullDateJsonDecoder)

Multipart Upload Example

    Publishers.CombineLatest(just(path: athletes), sessionProvider.jwt()).map {
        URLRequest.multipart(for: $0, 
                          method: .POST, 
                          headers: ["Authorization": $1, "Accept-Encoding": "gzip, deflate, br"], 
                          payload: value, 
                          multiparts: [Multipart(key: "profilePhoto", data: profileImageData, mimeType: .jpeg, fileName: "\(UUID().uuidString).jpeg")],
                          encoder: JSONEncoder.iso860JSONEncoder, 
                          decoder: JSONDecoder.iso8601FullDateJsonDecoder)
    }.flatMap {
        self.task(for: $0, decoder: JSONDecoder.iso8601FullDateJsonDecoder)
    }
    .eraseToAnyPublisher()
You might also like...
🌤 Swift Combine extensions for asynchronous CloudKit record processing

Swift Combine extensions for asynchronous CloudKit record processing. Designed for simplicity.

Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data.

Pigeon 🐦 Introduction Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data. It is heavily inspired by React Qu

AnalyticsKit for Swift is designed to combine various analytical services into one simple tool.

🦋 AnalyticsKit AnalyticsKit for Swift is designed to combine various analytical services into one simple tool. To send information about a custom eve

A command-line tool and Swift Package for generating class diagrams powered by PlantUML
A command-line tool and Swift Package for generating class diagrams powered by PlantUML

SwiftPlantUML Generate UML class diagrams from swift code with this Command Line Interface (CLI) and Swift Package. Use one or more Swift files as inp

A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.

ZamzamKit ZamzamKit is a Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and othe

Updeto is a simple package that help update checker for iOS Apps

Updeto is a simple package that will help you to check if the currently installed version is the same as the latest one available on App Store.

Swift implementation of the package url spec

PackageURL Swift implementation of the package url specification. Requirements Swift 5.3+ Usage import PackageURL let purl: PackageURL = "pkg:swift/a

Mechanical editing support for Package.swift manifests

Mechanical editing support for Package.swift manifests. Implements Swift Evolution proposal SE-301

Swift Package for Decoding RSS Feeds.

SyndiKit Swift Package built on top of XMLCoder for Decoding RSS Feeds. Check out the DocC-Built Site! Table of Contents Introduction Features Install

Owner
Daniel Mandea
👁🐝Ⅿ ∗ Swift ∗ Objc ∗ ReactNative * cpp
Daniel Mandea
Backward compatible async/await for URLSession!

URLSessionBackport URLSessionBackport aims to make it possible to use URLSession's new async/await syntax on older OSs, namely iOS 13 or macOS 10.15 a

Mochi Development, Inc. 39 Sep 21, 2022
Testable Combine Publishers - An easy, declarative way to unit test Combine Publishers in Swift

Testable Combine Publishers An easy, declarative way to unit test Combine Publishers in Swift About Combine Publishers are notoriously verbose to unit

Albert Bori 6 Sep 26, 2022
Call Swift functions from Rust with ease!

swift-rs Call Swift functions from Rust with ease! Todo Swift class deallocation from rust (implementing Drop and using deallocate_{type} methods) Mor

null 69 Dec 30, 2022
A cross-platform library of Swift utils to ease your iOS | macOS | watchOS | tvOS and Linux development.

Mechanica A library of Swift utils to ease your iOS, macOS, watchOS, tvOS and Linux development. Requirements Documentation Installation License Contr

Alessandro 28 Aug 28, 2022
Swift Package Manager plugin which runs ActionBuilder to create a Github Actions workflow for a swift package.

ActionBuilderPlugin A Swift Package Manager command which builds a Github Actions workflow for the current package. By default the workflow file will

Elegant Chaos 4 Jul 20, 2022
WordScramble app for demonstrating loading an external txt file and working with it

WordScramble-v2 WordScramble app for demonstrating loading an external txt file and working with it App for creating anagrams from given 8 letter word

Pavel Surový 0 Nov 30, 2021
Working alternative to Xcode previews.

SwiftUIPlaygrounds! A shell project you can use to iterate over SwiftUI interfaces using the HotReloading project. Instead of a "preview" the interfac

John Holdsworth 9 Dec 21, 2021
WholesomeExtensions - A SPM package that provides some extensions that I like to use

WholesomeExtensions This package includes some extensions that I like to use. Yo

Fırat Yenidünya 2 Dec 30, 2022
Handy Combine extensions on NSObject, including Set.

Storable Description If you're using Combine, you've probably encountered the following code more than a few times. class Object: NSObject { var c

hcrane 23 Dec 13, 2022
A simple Pokedex app written in Swift that implements the PokeAPI, using Combine and data driven UI.

SwiftPokedex SwiftPokedex is a simple Pokedex app written by Viktor Gidlöf in Swift that implements the PokeAPI. For full documentation and implementa

Viktor G 26 Dec 14, 2022