Swiftpack.co - Zhendryk/APIClient as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Zhendryk.
Zhendryk/APIClient 1.3.1
Pure Swift generic API interface allowing for easy fetching / creation of codable JSON data.
⭐️ 3
🕓 3 years ago
iOS
.package(url: "https://github.com/Zhendryk/APIClient.git", from: "1.3.1")

APIClient

A clean, generic interface from your application to an API, written in pure Swift with no other dependencies.

This library is made available as a Swift Package. To use it as a dependency in your project see this documentation from Apple.

Usage

General usage is as follows:

  1. Create your API client
let client = APIClient("api.github.com")
  1. Define your requests to the API you are interfacing with (see Source/Examples/Requests), and your Codable JSON objects to serialize the API's data into (see Source/Examples/Data Structures)
  2. Instantiate your request, send, and handle the response!
// Assuming a client named `client` has already been created...
// Create our request (see Source/Examples/Requests/GetPosts.swift)
let request = GetPosts(userId: 1)

// Send request
client.send(request: request, completion: { result in
    switch result {
    case .success(let (response, data)):
    // Handle your data here
    // In this case, data is serialized into a `Post` object (see Source/Examples/Data Structures/Post.swift)
        break
    case .failure(let error):
    // Handle your error here
        break
    }
})

GitHub

link
Stars: 3
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Release 1.3.1
3 years ago

Fixed a bug related to double encoding array HTTPParameters. Cleaned up the Send method. All requests now also return the URLResponse along with the data.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics