APIFreaks

1.0.1

api-freaks/af-swift-sdk

What's New

v1.0.1

2026-06-22T07:02:23Z

Updated the APIs for the SDK

Apifreaks Swift SDK

fern shield SwiftPM compatible

The Apifreaks Swift library provides convenient access to the Apifreaks APIs from Swift.

Table of Contents

Requirements

This SDK requires:

  • Swift 5.7+
  • iOS 15+
  • macOS 12+
  • tvOS 15+
  • watchOS 8+

Installation

With Swift Package Manager (SPM), add the following to the top-level dependencies array within your Package.swift file:

dependencies: [
    .package(url: "<git-url>", from: "1.0.1"),
]

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:

import Foundation
import APIFreaks

private func main() async throws {
    let client = APIFreaks()

    _ = try await client.bulkGeolocationLookup(
        apiKey: "apiKey",
        request: .init(ips: [
            "ips"
        ])
    )
}

try await main()

Environments

This SDK allows you to configure different environments for API requests.

import APIFreaks

let client = APIFreaks(
    ...,
    environment: .default
)

Errors

The SDK throws a single error enum for all failures. Client-side issues encoding/decoding failures and network errors use dedicated cases, while non-success HTTP responses are wrapped in an HTTPError that exposes the status code, a simple classification and an optional decoded message.

import APIFreaks

let client = APIFreaks(...)

do {
    let response = try await client.bulkGeolocationLookup(...)
    // Handle successful response
} catch let error as APIFreaksError {
    switch error {
    case .httpError(let httpError):
        print("Status code:", httpError.statusCode)
        print("Kind:", httpError.kind)
        print("Message:", httpError.body?.message ?? httpError.localizedDescription)
    case .encodingError(let underlying):
        print("Encoding error:", underlying)
    case .networkError(let underlying):
        print("Network error:", underlying)
    default:
        print("Other client error:", error)
    }
} catch {
    print("Unexpected error:", error)
}

Request Types

The SDK exports all request types as Swift structs. Simply import the SDK module to access them:

import APIFreaks

let request = Requests.BulkGeolocationLookupRequest(
    ...
)

Advanced

Additional Headers

If you would like to send additional headers as part of the request, use the additionalHeaders request option.

try await client.bulkGeolocationLookup(..., requestOptions: .init(
    additionalHeaders: [
        "X-Custom-Header": "custom value"
    ]
))

Additional Query String Parameters

If you would like to send additional query string parameters as part of the request, use the additionalQueryParameters request option.

try await client.bulkGeolocationLookup(..., requestOptions: .init(
    additionalQueryParameters: [
        "custom_query_param_key": "custom_query_param_value"
    ]
))

Timeouts

The SDK defaults to a 60-second timeout. Use the timeout option to configure this behavior.

try await client.bulkGeolocationLookup(..., requestOptions: .init(
    timeout: 30
))

Custom Networking Client

The SDK allows you to customize the underlying URLSession used for HTTP requests. Use the urlSession option to provide your own configured URLSession instance.

import Foundation
import APIFreaks

let client = APIFreaks(
    ...,
    urlSession: // Provide your implementation here
)

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon Jun 22 2026 01:34:02 GMT-0900 (Hawaii-Aleutian Daylight Time)