SwiftyNetworking: A SwiftUI-style approach to building networking layers

Hey everyone! :waving_hand:

I’d like to introduce SwiftyNetworking - a package I’ve been working on to make networking in Swift clearer, safer, and more composable way, taking strong inspiration from SwiftUI’s declarative patterns.

:brain: Motivation

It was a simple question:
What if building a request felt as natural as composing a SwiftUI view?

:puzzle_piece: Core Concept

The package centers on a Request protocol creating a final URLRequest via modifiers. Each modifier generates a ModifiedRequest with transformation logic and configuration, similar to SwiftUI's View and Environment. A Configuration store enables smooth, declarative request building and customization.

:gear: Quick Example

@Request struct ExampleRequest { let bar: String var body: some Request { Get("foo", bar, "buzz", from: ExampleService()) .headers { ApiKey(value: "sample_token") } .queryItems { Key("hello", value: "world") Key("foo", value: 42) } .responseBody(ExampleResponseModel.self) } } 
let session = Session() let result = try await session.send(request: ExampleRequest(bar: "buzz")) 

:locked: Authorization Support

SwiftyNetworking includes a built-in authorization mechanism.

You can define your own AuthorizationProvider based on the prepared abstraction. Once configured, you can mark any request with .authorize() modifier to set proper headers in the Request.

:package: Current Status

The package is currently at version 0.9, following a major refactor to align fully with Swift 6 concurrency.

The structure is now stable, with tests and mocks being the final step before 1.0 release.

:speech_balloon: Feedback

I’d love to hear your feedback!

  • Does the declarative approach make sense for you?

  • Would you be willing to review Swift's concurrency support?

  • Are you interested in contributing or testing the API?

Thanks for reading,

Piotr

Senior iOS Developer / Creator of SwiftyNetworking :rocket:

1 Like

I wonder if something like this could be done with the API mimicking the API established by the Network Framework on other platforms, including pre 26 version of Apple platforms.

@tera I have already sketched the abstraction that aims to completely isolate SwiftyNetworking from URLSession.

SessionProvider accepts Request and returns Response. Its implementation, through the use of URLSession, is currently default if it is possible to import Foundation.

The Network Framework could be easily incorporated as a SessionProvider. My goal was to separate the building Request process from sending it.