Member-only story
Avoid writing network requests by adopting Swift OpenAPI generator
Learn how you can reduce your network request complexity by adopting the generator
Eventually, almost every app must communicate with a backend service to retrieve and store data.
When we reach this point, we need to make network requests to our server API. Usually, we do this either by using a third-party lib or by creating our own network wrapper using URLSession. This is more than ok in most cases, however, we need to write some boilerplate code, define request and response models, maintain the code base if the server’s interface changes over time, and so on.
In WWDC 2023, Apple announced Swift Open API Generator: a set of tools to help us with this process. It relies on OpenAPI specification, an industry standard for declaring the functionality of our HTTP API.
Let’s quickly review how we can use it.
I’ll be using my Coffee Shop Demo app. If you’re interested, here’s the code.
I want to show a special section to show some deals we have for the day. So I created a simple API to return this information.
As I mentioned before, the Swift Open API generator is a project with a set of tools that help us interact with our server…