October 8th, 2025

A More Accessible NetworkKit

The first feedback on NetworkKit has been encouraging! The repo currently has 34 stars. A number that grows each week. I've also received some feedback that helped me think about version 1.2.0, available today!

Response typing

Until now, the response type was inferred by the type of the variable declared at the time of perform.

// Compiles with the type
let users: Response<[Users]> = try await client.perform(.getUsers)
 
// Doesn't compile without the type
// Generic parameter 'T' could not be inferred
let users = try await client.perform(.getUsers)

I generally prefer to explicitly type variables. But I have to admit that this behavior goes against NetworkKit's simplicity of use. Especially since you must add the generic type Response<>, which is specific to the package.

Faced with this observation, I quickly published a minor update that allowed associating the response type directly to the request.

@Get("/users", of: [User].self)
struct GetUsers {
    // The @Get macro adds the associated type
    // typealias Response = [Users]
}
 
// Now works without explicit type
let users = try await client.perform(.getUsers)

This method works, but I was quite unsatisfied with the syntax. Sometimes you have a response type that's specific to a single request. In this case, we'd like, as with @Body, to declare the type only in the request like this:

@Get("/users", GetUsers.ResponseDto.self)
struct GetUsers {
    struct ResponseDto: Decodable {
        let id: String
        let name: String
    }
}

But we end up with a longer and more complicated syntax. The complete opposite of what NetworkKit is supposed to solve.

The @Response macro

Like the @Body macro, the @Response macro brings a simple and elegant solution to this problem. It's now possible to declare the response type internally:

@Get("/user/:id")
struct GetUser {
    @Path
    let id: String
 
    @Response
    struct UserDto {
        let id: String
        let name: String
    }
}

Or to reuse an existing type like this:

@Get("/users")
@Response([User].self)
struct GetUsers { }

The syntax is now much clearer and more flexible!

Documentation

Speaking of accessibility, documentation is the entry point for devs to your package. Don't neglect it!

I've strengthened the package documentation overall and I've also published the DocC format documentation.

NetworkKit's DocC DocC format documentation allows you to quickly guide a dev on how to use your tool.

It contains some articles that help you quickly get started using the package as well as explanations of NetworkKit's references. Don't hesitate to give me feedback!

It's time to try it

I've been using NetworkKit professionally in large projects for several years and I've never been more satisfied with its efficiency. Maybe it's time to try it?

looping arrowfollow me here!
Snopia