Closed kean closed 2 years ago
With the new APIs, you'll be able to use URLRequest
, but what if you want to, let's say, change only the cache policy?
func send<Response>(
_ request: Request<Response>,
cachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy
) async throws -> Response where Response: Decodable
Another options to cover the latest requirement:
public struct RequestOptions {
public var cachePolicy: URLRequest.CachePolicy?
public var timeoutInterval: TimeInterval?
// Etc
}
public protocol APIClient2 {
public func send<T: Decodable>(
_ request: Request<T>,
options: RequestOptions = .init(),
delegate: URLSessionDataDelegate? = nil
) async throws -> Response<T>
}
Going with RequestOptions
and also a low-level API to send URLRequest
and decoding a request.
I'm considering redesigning the
APIClient
public API for Get 1.0. It was initially designed to accommodate only the most basic scenarios, but I'd like it to be more flexible. Here is a draft of a new API.Main Changes
URL
andURLRequest
in addition toRequest
URLSessionDataDelegate
for progress reporting, per-task auth, etc.Response<Data>
andResponse<String>
support fromsend(_:)
. If you usesend(_:)
, they'll just use the defaultDecodable
implementation for these types. You'll need to calldata(for:)
orstring(for:)
instead – faster, more discoverable, self-documenting