Perform network requests in your iOS app easier thanks to CombineNetworking

Maciej Burdzicki
2 min readJul 1, 2021
Photo by Florian Olivo on Unsplash

As a developer you’ve probably dealt with networking either to fetch content, authorize users or send some data to the servers. Before Apple’s Combine many developers were using AlamoFire framework to make networking easier to read and handle regardless if you use rxSwift or not. But now, with Combine, there’s no more need to use rx in iOS apps, nevertheless nice and easy framework for the network layer of your app would be nice to have, right?

Well… Here comes CombineNetworking. It’s crazy lightweight, easy to use framework that’s built using Combine and made specifically to work with it.

CombineNetworking is quite similar to Moya — wrapper for AlamoFire that makes it even more user friendly, except that CombineNetworking is a whole framework on its own.

So far you can install CombineNetworking only using CocoaPods, but in the near future it should also be possible to install CombineNetworking using Carthage and Swift Package Manager.

To install CombineNetworking using CocoaPods, just add this line to your Podfile.

pod CombineNetworking

In order to begin with CombineNetworking framework, you need to create endpoint. Endpoint can be a simple enum. Once you implement Endpoint protocol of CombineNetworking, you’ll be able to use it in order to perform network calls.

Ok. So far so easy. But what if your endpoint requires oauth access token to give you a valid response? CombineNetworking got you covered. All you need to do is to setup one more case to your TodosEndpoint, let’s call it “token” and implement optional variables of Endpoint protocol — requiresAccessToken and callbackPublisher.

Quite easy, right? You may now wonder — lookin’ good, but what about SSL and Certificate Pinning? Well… That’s also something CombineNetworking can deal with for you and it’s as easy as everything else with CombineNetworking.

Done. With just a few lines of code you’ve handled Certificate and/or SSL Pinning, automatic authorization mechanism and created an endpoint. All that’s left is to just make a call. And, as you probably guessed by now, it’s also a piece of cake. Just create an instance of CNProvider and call publisher() method which returns AnyPublisher which is one of object types Apple’s Combine comes with. Thanks to that you can effortlessly use CombineNetworking along with SwiftUI.

And that’s it. Your endpoint is ready and secure thanks to SSL and/or Certificate Pinning and oauth access token authorization, your todos are fetched and stored and the whole thing is easy to read and maintain.

To checkout the latest version of CombineNetworking, visit: https://github.com/neothXT/CombineNetworking

CombineNetworking is a fresh thing so feel free to share your feedback and if you have any ideas on how to improve it even more, it’d be highly appreciated. After all CombineNetworking was created to make developers lives a bit easier.

--

--