APSignedAPIClient

2.0.0

APSignedAPIClient is a Swift package for making signed API requests with HMAC-SHA256 authentication
aporat/APSignedAPIClient

What's New

2.0.0

2026-02-03T19:51:30Z

APSignedAPIClient

GitHub Actions Workflow Status codecov

APSignedAPIClient is a Swift package for making signed API requests with HMAC-SHA256 authentication. It provides a flexible, reusable client for iOS applications, leveraging Alamofire for networking. This package is designed to simplify secure API communication by handling request signing, authentication tokens, and error handling out of the box.

Features

  • Signed Requests: Automatically signs requests with HMAC-SHA256 using a client key.
  • Authentication: Supports account and user authentication tokens, plus device ID headers.
  • Configurable: Set base URL, app name, client version, and more via a single setup call.
  • Error Handling: Maps API-specific status codes to meaningful errors using APWebAuthentication.
  • Retry Logic: Includes a retrier for transient network failures and server errors.

Requirements

  • iOS 16.0+
  • Swift 5.9+
  • Xcode 15.0+

Installation

Swift Package Manager

Add APSignedAPIClient to your project via Swift Package Manager:

  1. In Xcode, go to File > Add Packages.
  2. Enter the repository URL:
    https://github.com/aporat/APSignedAPIClient.git
    
  3. Specify the version (e.g., 1.0.0) or use the latest commit.
  4. Add the package to your target.

Alternatively, add it to your Package.swift:

dependencies: [
    .package(url: "https://github.com/aporat/APSignedAPIClient.git", from: "1.0.0")
]

Then, include it in your target:

.target(
    name: "YourApp",
    dependencies: ["APSignedAPIClient"]
)

Usage

Setup

Configure the client with your API credentials and settings:

import APSignedAPIClient

CoreAPIClient.setup(
    baseURLString: "https://api.example.com",
    appName: "MyApp",
    clientVersion: "400",
    clientId: "your-client-id",
    clientKey: "your-client-key",
    userAgent: "MyApp/1.0"
)

Making a Request

Create an instance of CoreAPIClient and send a signed request:

let client = CoreAPIClient()

do {
    let request = try client.request(
    "/endpoint",
    method: .post,
    parameters: ["key": "value"]
)

request.responseData { response in
    switch response.result {
        case .success(let data):
            print("Response: \(data)")
        case .failure(let error):
            print("Error: \(client.generateError(response))")
        }
    }
} catch {
    print("Request creation failed: \(error)")
}

Dependencies

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

Last updated: Sun Mar 29 2026 22:49:02 GMT-0900 (Hawaii-Aleutian Daylight Time)