OkHttpClient

1.0.0

A lightweight HTTP client for Swift with logging and enhanced JSON support.
rmichelberger/OkHttpClient

What's New

1.0.0

2023-08-26T19:51:34Z

Initial release.

OkHttpClient

SwiftPM License: MIT

A leightweigth HTTP client for Swift projects.

Installing OkHttpClient

OkHttpClient supports Swift Package Manager.

Swift Package Manager

To install OkHttpClient using Swift Package Manager you can follow the tutorial published by Apple using the URL for the OkHttpClient repo with the current version:

  1. In Xcode, select “File” → “Add Packages...”
  2. Enter https://github.com/rmichelberger/OkHttpClient

or you can add the following dependency to your Package.swift:

.package(url: "https://github.com/rmichelberger/OkHttpClient/", from: "1.0.0")

Usage

func getItems() async throws -> [Item] {
    let client = OkHttpClient()
    let url = URL(...)
    let request = URLRequest(url: url)
    return try await client.execute(request)
}

Logger

You can specify the request and response logger.

let logger = SimpleLogger()
let client = OkHttpClient(logger: logger)

Data decoder

You can specify the data decoder. It's used to decode the response data.

The default is JSONDecoder.

let decoder = Decoder()
let client = OkHttpClient(decoder: decoder)

TODO

  • Improve unit test coverage.
  • Improve documentation.

Contributing

We always appreciate contributions from the community. Please make sure to cover your changes with unit tests.

Inspired by OkHttp.

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Oct 20 2024 14:19:32 GMT-0900 (Hawaii-Aleutian Daylight Time)