Skip to content

dr-bon/APIClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
    }
})

About

Pure Swift generic API interface allowing for easy fetching / creation of codable JSON data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published