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.
General usage is as follows:
let client = APIClient("api.github.com")
Source/Examples/Requests
), and your Codable
JSON objects to serialize the API's data into (see Source/Examples/Data Structures
)// 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
}
})
link |
Stars: 3 |
Last commit: 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