# Meet \`swift-api-client\` package

**URL:** <https://forums.swift.org/t/meet-swift-api-client-package/70550>\
**Category:** Community Showcase\
**Tags:** network, client, networking\
**Created:** [March 10, 2024, 10:35am UTC](https://forums.swift.org/t/meet-swift-api-client-package/70550 "2024-03-10T10:35:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dankinsoid](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dankinsoid/32/29286_2.png) [@dankinsoid](https://forums.swift.org/u/dankinsoid)\
**Post date:** [March 10, 2024, 10:35am UTC](https://forums.swift.org/t/meet-swift-api-client-package/70550/1 "2024-03-10T10:35:55Z")

</div>

[`swift-api-client`](https://github.com/dankinsoid/swift-api-client) is a comprehensive and modular Swift library for API design.

## Main Goals of the Library

- Minimalistic and intuitive syntax.
- Reusability, allowing for the injection of configurations across all requests.
- Extensibility and modularity.
- A simple core offering a wide range of possibilities.
- Facilitation of testing and mocking.

## Usage

The core of the library is the `APIClient` struct, serving both as a request builder and executor. It is a generic struct, enabling use for any task associated with `URLRequest`.

The branching and configuration injection/overriding capabilities of `APIClient`, extending to all its child instances, facilitate the effortless recycling of networking logic and tasks, thereby eliminating the need for copy-pasting.

While a full example is available in the [Example folder](https://github.com/dankinsoid/swift-networking/tree/main/Example), here is a simple usage example:

```swift
let client = APIClient(url: baseURL)
  .bodyDecoder(.json(dateDecodingStrategy: .iso8601))
  .bodyEncoder(.json(dateEncodingStrategy: .iso8601))
  .errorDecoder(.decodable(APIError.self))
  .tokenRefresher { client, _ in
    try await client("token").get()
  } auth: {
    .bearer($0)
  }

// Create a `APIClient` instance for the /users path
let usersClient = client("users")

// GET /users?name=John&limit=1
let john: User = try await usersClient
  .query(["name": "John", "limit": 1])
  .auth(enabled: false)
  .get()

// Create a `APIClient` instance for /users/{userID} path
let johnClient = usersClient(john.id)

// GET /user/{userID}
let user: User = try await johnClient.get()

// PUT /user/{userID}
try await johnClient.body(updatedUser).put()

// DELETE /user/{userID}
try await johnClient.delete()

```

---

<div class="post-metadata">

**Author:** ![MPLewis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mplewis/32/40019_2.png) [@MPLewis](https://forums.swift.org/u/MPLewis)\
**Post date:** [March 10, 2024, 8:08pm UTC](https://forums.swift.org/t/meet-swift-api-client-package/70550/2 "2024-03-10T20:08:09Z")

</div>

I have some feedback about your naming - putting “networking” in the name made me immediately think this was about low-level TCP/UDP networking instead of high-level HTTP requests, and your ReadMe took a long time to reveal that’s what the package is about. You might want to consider changing the name and/or making it clear at the top of the ReadMe what portion of the networking stack you’re dealing with.

---

<div class="post-metadata">

**Author:** ![dankinsoid](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dankinsoid/32/29286_2.png) [@dankinsoid](https://forums.swift.org/u/dankinsoid)\
**Post date:** [March 10, 2024, 9:42pm UTC](https://forums.swift.org/t/meet-swift-api-client-package/70550/3 "2024-03-10T21:42:22Z")

</div>

thanks, i'll think about it
