This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.hadihariri.js.basics | |
import js.dom.html.document | |
fun main(args: Array<String>) { | |
document.getElementById("email").setAttribute("value", "[email protected]") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>This page is manipulated with Kotlin</title> | |
</head> | |
<body> | |
<input type="text" id="email"> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Customer(val name: String, val email: String, val country: String) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun isValidAccount(accountNumber: String): Boolean { | |
// function logic | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val appServer = AppServer() | |
appServer.resolveDependencies(ContainerConfiguration) // this is the IoC container configuration | |
appServer.get("/customers", { | |
with<Database> { | |
response.send(getCustomers()) // see below why this works |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Customer(val id: Int, val name: String, val email: String, val country: String) | |
val customerList = arrayListOf<Customer>( | |
Customer(1, "Joe Smith", "[email protected]", "UK"), | |
Customer(2, "Jack Jones", "[email protected]", "US"), | |
Customer(3, "Maria Gonzalez", "[email protected]", "Spain") | |
) | |
fun main(args: Array<String>) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Customer(val name: String, val email: String, val country: String) | |
val customerList = object : ArrayList<Customer>() { | |
} | |
fun main(args: Array<String>) { | |
// fill up some dummy customers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server.get("/book", | |
{ | |
response.negotiate ( | |
"text/html" with { send("Something about me") }, | |
"application/json" with { send("{title: 'Something about me', isbn: 'IS454-12123-A23232'}")} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
negotiate ( | |
"text/html" to { response.send("Something about me")}, | |
"application/json" to { | |
response.send("{title: 'Something about me', isbn: 'IS454-12123-A23232'}") | |
} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server.get("/book", | |
{ | |
// automatic negotiation exists, but if you want manual... | |
negotiate { | |
on("text/html") {response.send("Something about everyone")} | |
on("application/json") { | |
// this is just a sample. automatic json serialization is also available... |