Last active
October 7, 2021 14:09
-
-
Save gtokman/329dac1248700e291efd68b4a6492734 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/// Fetch API data for `Endpoint` | |
struct ApiService { | |
let businesses: (YelpEndpoint) async throws -> [Business] | |
} | |
extension ApiService { | |
/// Live service used in App | |
static let live = ApiService { endpoint in | |
let (data, error) = try await URLSession.shared.data(for: endpoint.request) | |
let decoder = JSONDecoder() | |
decoder.keyDecodingStrategy = .convertFromSnakeCase | |
let response = try decoder.decode(SearchResult.self, from: data) | |
return response.businesses | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment