2018-05-18 16:04:31 +10:00
|
|
|
package com.baeldung.kotlinjs
|
|
|
|
|
|
|
|
external fun require(module: String): dynamic
|
|
|
|
|
2018-05-21 22:16:09 +10:00
|
|
|
data class CryptoCurrency(var name: String, var price: Float)
|
|
|
|
|
2018-05-18 16:04:31 +10:00
|
|
|
fun main(args: Array<String>) {
|
|
|
|
println("Crypto Currency price API!")
|
|
|
|
val express = require("express")
|
|
|
|
val app = express()
|
|
|
|
|
|
|
|
app.get("/crypto", { _, res ->
|
2018-05-21 22:16:09 +10:00
|
|
|
println(generateCryptoRates())
|
|
|
|
res.send(generateCryptoRates())
|
2018-05-18 16:04:31 +10:00
|
|
|
})
|
|
|
|
|
|
|
|
app.listen(3000, {
|
|
|
|
println("Listening on port 3000")
|
|
|
|
})
|
2018-05-21 22:16:09 +10:00
|
|
|
}
|
|
|
|
fun generateCryptoRates(): Array<CryptoCurrency>{
|
|
|
|
val crytoCurrency = arrayOf<CryptoCurrency>(CryptoCurrency("Bitcoin",
|
|
|
|
90000F), CryptoCurrency("ETH",1000F),
|
|
|
|
CryptoCurrency("TRX",10F));
|
|
|
|
return crytoCurrency
|
2018-05-18 16:04:31 +10:00
|
|
|
}
|