Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kean/APIClient
Web API client built using async/await
https://github.com/kean/APIClient
Last synced: 3 months ago
JSON representation
Web API client built using async/await
- Host: GitHub
- URL: https://github.com/kean/APIClient
- Owner: kean
- License: mit
- Created: 2021-11-19T19:35:32.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-25T19:45:58.000Z (6 months ago)
- Last Synced: 2024-05-02T16:18:39.544Z (6 months ago)
- Language: Swift
- Homepage:
- Size: 2.68 MB
- Stars: 897
- Watchers: 10
- Forks: 71
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - APIClient
README
# Get
[![Platform](https://img.shields.io/badge/Platforms-iOS%20%7C%20macOS%20%7C%20watchOS%20%7C%20tvOS%20%7C%20Linux-4E4E4E.svg?colorA=28a745)](#installation)
A lean Swift web API client built using async/await.
Get provides a clear and convenient API for modeling network requests using `Request` type. And its `APIClient` makes it easy to execute these requests and decode the responses.
```swift
// Create a client
let client = APIClient(baseURL: URL(string: "https://api.github.com"))// Start sending requests
let user: User = try await client.send(Request(path: "/user")).valuevar request = Request(path: "/user/emails", method: .post, body: ["[email protected]"])
try await client.send(request)
```The client uses `URLSession` for networking and provides complete access to all its APIs. It is designed with the "less is more" idea in mind and doesn't introduce any unnecessary abstractions on top of native APIs.
```swift
// In addition to `APIClientDelegate`, you can also override any methods
// from `URLSessionDelegate` family of APIs.
let client = APIClient(baseURL: URL(string: "https://api.github.com")) {
$0.sessionDelegate = ...
}// You can also provide task-specific delegates and easily change any of
// the `URLRequest` properties before the request is sent.
let delegate: URLSessionDataDelegate = ...
let response = try await client.send(Paths.user.get, delegate: delegate) {
$0.cachePolicy = .reloadIgnoringLocalCacheData
}
```In addition to sending quick requests, it also supports downloading data to a file, uploading from a file, authentication, auto-retries, logging, and more. It's a kind of code that you would typically write on top of `URLSession` if you were using it directly.
## Sponsor 💖
[Support](https://github.com/sponsors/kean) Get on GitHub Sponsors.
## Documentation
Learn how to use Get by going through the [documentation](https://kean-docs.github.io/get/documentation/get/) created using DocC.
To learn more about `URLSession`, see [URL Loading System](https://developer.apple.com/documentation/foundation/url_loading_system).
## Integrations
### Pulse
You can easily add logging to your API client using [Pulse](https://github.com/kean/Pulse). It requests a single line to setup.
```swift
let client = APIClient(baseURL: URL(string: "https://api.github.com")) {
$0.sessionDelegate = PulseCore.URLSessionProxyDelegate()
}
```With Pulse, you can inspect logs directly on your device – and it supports _all_ Apple platforms. And you can share the logs at any time and view them on a big screen using [Pulse Pro](https://kean.blog/pulse/pro).
### CreateAPI
With [CreateAPI](https://github.com/kean/CreateAPI), you can take your backend OpenAPI spec, and generate all of the response entities and even requests for Get `APIClient`.
```swift
generate api.github.yaml --output ./OctoKit --module "OctoKit"
```> Check out [App Store Connect Swift SDK](https://github.com/AvdLee/appstoreconnect-swift-sdk) that uses [CreateAPI](https://github.com/kean/CreateAPI) for code generation.
### Other Extensions
Get is a lean framework with a lot of flexibility and customization points. It makes it very easy to learn and use, but you'll need to install additional modules for certain features.
- [Mocker](https://github.com/WeTransfer/Mocker) – mocking network requests for testing purposes
- [URLQueryEncoder](https://github.com/CreateAPI/URLQueryEncoder) – URL query encoder with `Codable` support
- [MultipartFormDataKit](https://github.com/Kuniwak/MultipartFormDataKit) – adds support for `multipart/form-data`
- [NaiveDate](https://github.com/CreateAPI/NaiveDate) – working with dates without timezones## Minimum Requirements
| Get | Date | Swift | Xcode | Platforms |
|------|--------------|-------|-------|------------------------------------------------------|
| 2.2 | Apr 13, 2024 | 5.8 | 14.3 | iOS 13.0, watchOS 6.0, macOS 10.15, tvOS 13.0, Linux |
| 2.0 | Jul 26, 2022 | 5.5 | 13.3 | iOS 13.0, watchOS 6.0, macOS 10.15, tvOS 13.0, Linux |## License
Get is available under the MIT license. See the LICENSE file for more info.