diff --git a/swift/Sources/OpenMeteoSdk/OpenMeteoSdk.swift b/swift/Sources/OpenMeteoSdk/OpenMeteoSdk.swift index cd347cf..cff4e95 100644 --- a/swift/Sources/OpenMeteoSdk/OpenMeteoSdk.swift +++ b/swift/Sources/OpenMeteoSdk/OpenMeteoSdk.swift @@ -14,7 +14,15 @@ extension WeatherApiResponse { @available(iOS 13.0.0, *) @available(macOS 12.0, *) public static func fetch(url: URL, session: URLSession = URLSession.shared) async throws -> [WeatherApiResponse] { - let (data, response) = try await session.data(from: url) + var request = URLRequest(url: url) + return try await fetch(request: request, session: session) + } + + @available(iOS 13.0.0, *) + @available(macOS 12.0, *) + /// Fetch data using a given URLRequest and decode the Open-Meteo Weather API Flatbuffers structure + public static func fetch(request: URLRequest, session: URLSession = URLSession.shared) async throws -> [WeatherApiResponse] { + let (data, response) = try await session.data(for: request) guard let res = (response as? HTTPURLResponse) else { throw OpenMeteoSdkError.error(message: "response is not type HTTPURLResponse") }