Skip to content

Instantly share code, notes, and snippets.

@gtokman
Last active October 7, 2021 14:09
Show Gist options
  • Save gtokman/329dac1248700e291efd68b4a6492734 to your computer and use it in GitHub Desktop.
Save gtokman/329dac1248700e291efd68b4a6492734 to your computer and use it in GitHub Desktop.
/// 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