Стефан Јовановић
11/12/2023, 7:43 AMclass ProductApi {
private val baseUrl = "<https://fakestoreapi.com/>"
private val httpClient = HttpClient {
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
}
suspend fun fetchProducts(limit: Int): Flow<List<Product>> {
return flow {
// Delay to show a loading state.
delay(2000)
try {
emit(httpClient.get(urlString = "${baseUrl}products?limit=$limit").body())
} catch (e: Exception) {
emit(emptyList())
}
}
}
}
Filip Dolník
11/12/2023, 8:31 AMfetchProducts
non suspending - it doesn’t have to be suspending in your case.print(Skie.self)
to the Swift code (assuming you are on a 0.5.x version) or by looking at the generated Swift code which is located in the build/skie/$frameworkPath/swift/generated
Стефан Јовановић
11/12/2023, 9:15 AM