Skip to content

Commit b1f6b02

Browse files
committed
[BAEL-1170] Removed upstream API
1 parent 0222fba commit b1f6b02

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
package com.baeldung.kotlinjs
22

3-
import kotlin.js.Json
4-
53
external fun require(module: String): dynamic
64

5+
data class CryptoCurrency(var name: String, var price: Float)
6+
77
fun main(args: Array<String>) {
88
println("Crypto Currency price API!")
9-
109
val express = require("express")
11-
val request = require("request");
12-
1310
val app = express()
1411

15-
//coin market api to fetch latest crypto currencies prices
16-
val url = "https://api.coinmarketcap.com/v2/ticker/?limit=10"
17-
1812
app.get("/crypto", { _, res ->
19-
request(url) { error: String?, _, body: String ->
20-
res.type("application/json")
21-
if (error.isNullOrEmpty()) {
22-
val data: dynamic = JSON.parse<Json>(body)
23-
res.send(data);
24-
} else {
25-
println(error)
26-
res.send(error);
27-
}
28-
}
29-
13+
println(generateCryptoRates())
14+
res.send(generateCryptoRates())
3015
})
3116

3217
app.listen(3000, {
3318
println("Listening on port 3000")
3419
})
20+
}
21+
fun generateCryptoRates(): Array<CryptoCurrency>{
22+
val crytoCurrency = arrayOf<CryptoCurrency>(CryptoCurrency("Bitcoin",
23+
90000F), CryptoCurrency("ETH",1000F),
24+
CryptoCurrency("TRX",10F));
25+
return crytoCurrency
3526
}

0 commit comments

Comments
 (0)