26 lines
746 B
Kotlin
Raw Normal View History

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)
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())
})
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
}