Contents

rmichelberger/okhttpclient

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)

RetroSwift

OkHttpClient is best used together with RetroSwift.

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.

Package Metadata

Repository: rmichelberger/okhttpclient

Default branch: main

README: README.md