25 lines
676 B
Swift
25 lines
676 B
Swift
import Foundation
|
|
|
|
struct APIEnvironment {
|
|
let baseURL: URL
|
|
}
|
|
|
|
struct HermesAPIClient {
|
|
let environment: APIEnvironment
|
|
let session: URLSession
|
|
|
|
init(environment: APIEnvironment, session: URLSession = .shared) {
|
|
self.environment = environment
|
|
self.session = session
|
|
}
|
|
|
|
func get(path: String) async throws -> (Data, HTTPURLResponse) {
|
|
let url = environment.baseURL.appendingPathComponent(path)
|
|
let (data, response) = try await session.data(from: url)
|
|
guard let httpResponse = response as? HTTPURLResponse else {
|
|
throw URLError(.badServerResponse)
|
|
}
|
|
return (data, httpResponse)
|
|
}
|
|
}
|