This repository shows how handle Rest API's in SwiftUI and Combine

Overview

SwiftUI-Combine-Networking

This repository shows how handle Rest API's in SwiftUI and Combine

  • Endpoints enum includes paths which will be added the end of base URL

  • QueryItems enum includes parameters for requests Example to authenticate user, we need to email and password from user

  • httpMethods enum includes some main httpmethods GET, POST, PUT, PATCH, DELETE

Example of usages

GET REQUEST

NetworkingManager.instance
            .requestPublisher(endpoint: .listUser)
            .decode(type: [UserModel].self, decoder: JSONDecoder())
            .receive(on: DispatchQueue.main)
            .sink { completion in
                print(completion)
            } receiveValue: {[unowned self] arrayModel in
                print(arrayModel)
               // self.arrayModel = arrayModel
            }.store(in: &cancallable)

POST REQUEST

 NetworkingManager.instance
            .requestPublisher(parameters:.createUser(name: name, job: job),method: .POST, endpoint: .users)
            .decode(type: ResponseModel.self, decoder: JSONDecoder())
            .receive(on: DispatchQueue.main)
            .sink { completion in
                print(completion)
            } receiveValue: {[unowned self] response in
                print(response)
                //check response to see whats going on
            }.store(in: &cancallable)

PUT REQUEST

 NetworkingManager.instance
            .requestPublisher(parameters:.updateUser(name: name, job: job),method: .PUT, endpoint: .updateUser)
            .decode(type: NewUserModel.self, decoder: JSONDecoder())
            .receive(on: DispatchQueue.main)
            .sink { completion in
                print(completion)
            } receiveValue: {[unowned self] response in
                print(response)
                //response can return a boolean which indicates request was succesfull or not
            }.store(in: &cancallable)

DELETE REQUEST

  • All user will be deleted
   NetworkingManager.instance
            .requestPublisher(method: .DELETE, endpoint: .users)
            .decode(type: DeleteResponse.self, decoder: JSONDecoder())
            .receive(on: DispatchQueue.main)
            .sink { completion in
                print(completion)
            } receiveValue: {[unowned self] response in
                print(response)
            }.store(in: &cancallable)

Warning

  • if models are not matches response, you may get fail while decoding.
  • more public requests can be find https://reqres.in/ website
You might also like...
PowerfulCombine - A simple suite of Combine helpers
PowerfulCombine - A simple suite of Combine helpers

A package with powerful combine extensions. 🤟 Motivation The Combine framework

This a simple swiftui app where i used mvvm architecture, coredata swiftui and so on..
This a simple swiftui app where i used mvvm architecture, coredata swiftui and so on..

SwiftUI MVVM COREDATA NOTE APP This a simple swiftui app where i used mvvm architecture, coredata swiftui and so on... #FEATURES SWIFTUI MVVM COREDATA

MockChat TDD MVVM SwiftUI - Mockable, Test driven Development, clear Architecture example using SwiftUI
MockChat TDD MVVM SwiftUI - Mockable, Test driven Development, clear Architecture example using SwiftUI

MockChat_TDD_MVVM_SwiftUI Mockable, Test driven Development, clear Architecture

Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets.
Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets.

SwiftUI-LazyVGrid Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets. Screenshots Samples IP & Credits All those b

ProductListSwiftUI - SwiftUI Project to fetch product list using the fakestoreapi and the MVVM architectural pattern
ProductListSwiftUI - SwiftUI Project to fetch product list using the fakestoreapi and the MVVM architectural pattern

ProductListSwiftUI SwiftUI Project to fetch product list using the fakestoreapi

⚛️ A Reactive Data-Binding and Dependency Injection Library for SwiftUI x Concurrency.
⚛️ A Reactive Data-Binding and Dependency Injection Library for SwiftUI x Concurrency.

SwiftUI Atom Properties A Reactive Data-Binding and Dependency Injection Library for SwiftUI x Concurrency 📔 API Reference Introduction Examples Gett

SwiftUI iOS component for Step Indications.
SwiftUI iOS component for Step Indications.

StepperView SwiftUI iOS component for Step Indications Table of Contents Features Documentation Installation CocoaPods Carthage Swift Package Manager

SwiftUI module library for adding seasons theme animations to your app
SwiftUI module library for adding seasons theme animations to your app

HolidayThemes SwiftUI module library for adding seasons theme animations to your app. Requirements iOS 13.0+ Xcode 12.0+ Installation Swift Package Ma

SFSymbols SwiftUI Enum
SFSymbols SwiftUI Enum

SF SFSymbols SwiftUI Enum Example: All lines are equivalent. Image(systemName: "square.fill.and.line.vertical.square.fill") Image(systemName:

Owner
Abdullah Kardaş
Android & IOS Developer
Abdullah Kardaş
This repo shows how to set up and use GitHub Actions as a CI for Swift Packages

SwiftPackageWithGithubActionsAsCI This repo shows how to set up and use GitHub Actions as a CI for Swift Packages. Available environments on GitHib Li

Michał Tynior 0 Nov 3, 2021
A demo demonstrates how to use combine and MVVM in the SwiftUI app

SwiftUI-MVVM-Combine A demo demonstrates how to use combine and MVVM in the Swif

Asa. Ga 7 Jul 5, 2022
A sample project exploring MVVM pattern with SwiftUI/Combine, using Unsplash API (via Picsum.photos API)

CombineUnsplash A sample project exploring MVVM pattern with SwiftUI/Combine, using Unsplash API (via Picsum.photos API) with detail example. Resource

Vinh Nguyen 26 Dec 13, 2022
This repository is for an assignment

ArticlesTask This repository is for an assignment How to run the app Pull the latest code from "https://github.com/ahmed23khan/ArticlesTask.git" Open

Tauqeer Ahmed Khan 0 Nov 25, 2021
Bonjourr-Safari - Safari repository for Bonjourr

Install Start Clone this repo & the original repo Open Bonjourr Startpage.xcodep

Victor Azevedo 2 Nov 29, 2022
RealmSwift, MVVM with Repository, DI, Coordinators,

Todo_App_With_RealmDB Lol, just playing around because I'm bored ?? Refreshing usage of Realm, been a while. New updates look cool though (first time

Emmanuel Omokagbo 2 Aug 4, 2022
iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit

iOS (Swift 5): MVVM test with Combine and UIKit MVVM and functional reactive programming (FRP) are very used in iOS development inside companies. Here

Koussaïla BEN MAMAR 2 Dec 31, 2021
Tech blog about Put Generic Protocol as Variable Type. How Combine Publisher put into AnyPublisher

How to Put Generic Protocol as Variable Type Have you ever put a Protocol on a variable? I believe you do. The Delegate pattern is using a lot in UIKi

Tsungyu Yu 8 Aug 17, 2021
Mini-application iOS native avec Xcode et Swift exploitant l'architecture MVVM et le framework Combine d'Apple pour la mise en place de la programmation réactive fonctionnelle, le tout avec UIKit.

iOS (Swift 5): Test MVVM avec Combine et UIKit L'architecture MVVM et la programmation réactive fonctionnelle sont très utlisées dans le développement

Koussaïla BEN MAMAR 2 Nov 5, 2022
MVVM-RXSWIFT-COMBINE- - Demo application populating posts from network request using

MVVM => RXSWIFT + COMBINE Demo application populating posts from network request

Amr Al-khayat 0 Jan 2, 2022