Introducing Froggy: Composable networking for modern Swift apps
Our team has been hard at work over the past few months writing a whole lot of networking code in Swift. This means we’re repeating ourselves with a heck of a lot of boiler-plate — stuff that could be solved using some of the wonderful language features at our disposal in the latest versions of Swift. So, we put together Froggy, a library for composable, concurrent networking for modern Swift applications. Froggy provides an extremely lightweight layer over the Foundation networking APIs to make it ultra-easy to compose complex requests.
Froggy provides an extremely lightweight layer over the Foundation networking APIs to make it ultra-easy to compose complex requests.
We put together Froggy with a few goals in mind:
Run and map URLSession tasks to custom objects in a single function call
Compose URLRequest objects using natural, composable syntax (kinda like SwiftUI modifiers)
Easily add authentication and standard headers to requests
Errors are handled and mapped out of the box, making it easy to understand what went wrong (if anything)
Safely set the expected HTTP Method
We’ve found that most networking libraries are mega-overkill for 99% of networking needs and that the Foundation APIs do the job wonderfully. But, it is Foundation we’re talking about… a library that’s been around since the early Cocoa days of Mac OS X. Enter Froggy to take advantage of the latest and greatest patterns in Swift and bridge the gap with the Foundation APIs.
Composing a request, firing it off, and getting the response object is incredibly easy:
let request = baseURL
.addPath(TestPaths.fact)
.addQueryItems([
URLQueryItem(name: "max_length", value: "80")
])
.request()
let session = URLSession(configuration: .default)
let response: DataSourceResponse<CatFactResponse> = try? await session.run(request)
Froggy is very opinionated, but is extremely lightweight. We hope you’ll find it useful in your apps!
Why Froggy? 🐸
Naming is hard. Frogs are cool. Somehow the word association from "network" to "web" to "webbed feet" to "frogs" just made sense.