forked from supabase-community/postgrest-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PostgrestHTTPClient and remove non-concurrency method versions (s…
…upabase-community#33) * Add PostgrestHTTPClient * Make default http client public * Format
- Loading branch information
Showing
13 changed files
with
89 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Foundation | ||
|
||
public protocol PostgrestHTTPClient { | ||
func execute(_ request: URLRequest) async throws -> (Data, HTTPURLResponse) | ||
} | ||
|
||
public struct DefaultPostgrestHTTPClient: PostgrestHTTPClient { | ||
public init() {} | ||
|
||
public func execute(_ request: URLRequest) async throws -> (Data, HTTPURLResponse) { | ||
try await withCheckedThrowingContinuation { continuation in | ||
let dataTask = URLSession.shared.dataTask(with: request) { data, response, error in | ||
if let error = error { | ||
continuation.resume(throwing: error) | ||
return | ||
} | ||
|
||
guard | ||
let data = data, | ||
let httpResponse = response as? HTTPURLResponse | ||
else { | ||
continuation.resume(throwing: URLError(.badServerResponse)) | ||
return | ||
} | ||
|
||
continuation.resume(returning: (data, httpResponse)) | ||
} | ||
|
||
dataTask.resume() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.