diff --git a/Web/Sources/Web/WebServices/TransportJSON.swift b/Web/Sources/Web/WebServices/TransportJSON.swift index ff8dee89f..c0c4876df 100644 --- a/Web/Sources/Web/WebServices/TransportJSON.swift +++ b/Web/Sources/Web/WebServices/TransportJSON.swift @@ -10,6 +10,20 @@ import Foundation extension Transport { + public func send(request: URLRequest, resultType: R.Type, dateDecoding: JSONDecoder.DateDecodingStrategy = .iso8601, keyDecoding: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys) async throws -> (HTTPURLResponse, R?) { + + try await withCheckedThrowingContinuation { continuation in + self.send(request: request, resultType: resultType, dateDecoding: dateDecoding, keyDecoding: keyDecoding) { result in + switch result { + case .success(let (response, decoded)): + continuation.resume(returning: (response, decoded)) + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + /** Sends an HTTP get and returns JSON object(s) */ @@ -121,6 +135,22 @@ extension Transport { } } + + public func send(request: URLRequest, method: String, data: Data, resultType: R.Type, dateDecoding: JSONDecoder.DateDecodingStrategy = .iso8601, keyDecoding: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys) async throws -> (HTTPURLResponse, R?) { + + try await withCheckedThrowingContinuation { continuation in + self.send(request: request, method: method, data: data, resultType: resultType, dateDecoding: dateDecoding, keyDecoding: keyDecoding) { result in + + switch result { + case .success(let (response, decoded)): + continuation.resume(returning: (response, decoded)) + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + /** Sends the specified HTTP method with a Raw payload and returns JSON object(s). */