diff --git a/kotlin-js/src/main/kotlin/com/baeldung/kotlinjs/CryptoRate.kt b/kotlin-js/src/main/kotlin/com/baeldung/kotlinjs/CryptoRate.kt index e0a289149a..8df43f9205 100755 --- a/kotlin-js/src/main/kotlin/com/baeldung/kotlinjs/CryptoRate.kt +++ b/kotlin-js/src/main/kotlin/com/baeldung/kotlinjs/CryptoRate.kt @@ -1,35 +1,26 @@ package com.baeldung.kotlinjs -import kotlin.js.Json - external fun require(module: String): dynamic +data class CryptoCurrency(var name: String, var price: Float) + fun main(args: Array) { println("Crypto Currency price API!") - val express = require("express") - val request = require("request"); - val app = express() - //coin market api to fetch latest crypto currencies prices - val url = "https://api.coinmarketcap.com/v2/ticker/?limit=10" - app.get("/crypto", { _, res -> - request(url) { error: String?, _, body: String -> - res.type("application/json") - if (error.isNullOrEmpty()) { - val data: dynamic = JSON.parse(body) - res.send(data); - } else { - println(error) - res.send(error); - } - } - + println(generateCryptoRates()) + res.send(generateCryptoRates()) }) app.listen(3000, { println("Listening on port 3000") }) +} +fun generateCryptoRates(): Array{ + val crytoCurrency = arrayOf(CryptoCurrency("Bitcoin", + 90000F), CryptoCurrency("ETH",1000F), + CryptoCurrency("TRX",10F)); + return crytoCurrency } \ No newline at end of file