Local SPM package wrapping Outline's RPC-style REST API — auth, documents, collections, and search — behind a protocol boundary (OutlineAPIClient) so the app never depends on the transport directly.
23 lines
773 B
Swift
23 lines
773 B
Swift
import Foundation
|
|
|
|
/// Thin seam over `URLSession` so `LiveOutlineAPIClient` can be tested without network access.
|
|
public protocol HTTPClient: Sendable {
|
|
func send(_ request: URLRequest) async throws -> (Data, HTTPURLResponse)
|
|
}
|
|
|
|
public final class URLSessionHTTPClient: HTTPClient, Sendable {
|
|
private let session: URLSession
|
|
|
|
public init(session: URLSession = .shared) {
|
|
self.session = session
|
|
}
|
|
|
|
public func send(_ request: URLRequest) async throws -> (Data, HTTPURLResponse) {
|
|
let (data, response) = try await session.data(for: request)
|
|
guard let httpResponse = response as? HTTPURLResponse else {
|
|
throw OutlineAPIError.transport(URLError(.badServerResponse))
|
|
}
|
|
return (data, httpResponse)
|
|
}
|
|
}
|