[BAEL-1170] Removed upstream API
This commit is contained in:
parent
0222fbaf45
commit
b1f6b024fc
|
@ -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<String>) {
|
||||
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<Json>(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<CryptoCurrency>{
|
||||
val crytoCurrency = arrayOf<CryptoCurrency>(CryptoCurrency("Bitcoin",
|
||||
90000F), CryptoCurrency("ETH",1000F),
|
||||
CryptoCurrency("TRX",10F));
|
||||
return crytoCurrency
|
||||
}
|
Loading…
Reference in New Issue