Create a Beautiful Network Layer to Interact with your API in Swift (2022)

Mark van Wijnen
5 min readJul 3, 2022
Photo by Balázs Kétyi on Unsplash

This story is an iteration, my spin, on the original story Create a beautiful Network Layer With Swift written by Ertem Biyik. He starts by writing:

“Barely all swift developers once upon a time face with a task of interacting with API’s.”

I agree. Many, if not all, developers will face having to interact with an API of some sort at some point in their career. Although I have no problem writing code myself to interact with API’s, there are so many different API’s and so many approaches to writing code to interact with them. I was interested to see which approach he choose and what he considered scalable, clean and pretty.

Let’s first get something out of the way. He did a good job. However my expectations were to find code that was using some of the modern tools we got over the years like the Combine framework, Tasks and Concurrency (Async/Await). So the approach he went with, felt a bit, outdated. Which I noticed from the comments I wasn’t the only one to think that. So I took it to myself to rewrite his story in an attempt to present my view of a more modern approach. Hopefully it will be useful to some people.

The Rick and Morty API

--

--

Mark van Wijnen

macOS/iPadOS/iOS/watchOS/visionOS developer and SwiftUI enthousiast. “Stay Hungry, Stay Foolish!” — Steve Jobs