Files
Outpost/OutlineKit/Sources/OutlineKit/Networking/HTTPClient.swift
T
Puranjay Savar Mattas 07fb08cb6b feat(outlinekit): add REST client package for Outline API
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.
2026-08-14 00:23:12 +01:00

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)
}
}