This presentation explains how to use the Spark framework together with the Kotlin programming language and the JVM to build robust APIs. The presentation begins with some basics about the Kotlin language from JetBrains. It then gives a brief introduction to Spark, a Sinatra-inspired framework for setting up Web routes. It concludes with some references to three blog posts with more explanation and a GitHub repository where the sample code can be found.
2. Intro & Agenda
• Why Kotlin
• Some basics of the syntax
• Quick intro to Spark
• Using Kotlin & Spark together
@travisspencer / @nordicapis
3. Why Kotlin
• Compiles to JVM bytecode and JavaScript
• From industry not academia
• Open source & costs nothing to adopt
• Can use existing Java or JavaScript frameworks
• Very low learning curve
@travisspencer / @nordicapis
4. Why Kotlin
• Supports OO and functional programming styles
• Excellent IDE support (Intellij and Eclipse)
• Perfect for Java & Android shops
• Strong commercial support from
@travisspencer / @nordicapis
6. • fun keyword
• Return type (Unit
default)
Basic Syntax
@travisspencer / @nordicapis
7. • fun keyword
• Return type (Unit
default)
• Types of args after
names
Basic Syntax
@travisspencer / @nordicapis
8. • fun keyword
• Return type (Unit
default)
• Types of args after
names
Basic Syntax
@travisspencer / @nordicapis
• Named arguments
9. • fun keyword
• Return type (Unit
default)
• Types of args after
names
Basic Syntax
@travisspencer / @nordicapis
• Named arguments
• Single expression
functions
19. Controller Overloads
• Override
• Named arguments
(again)
• mapOf standard function
• to keyword to nicely
define associative array
@travisspencer / @nordicapis
40. • Intro to Spark - http://goo.gl/oPm0jV
• Kotlin + Spark blog post
• Part 1 - http://goo.gl/WlxKQq
• Part 2 - http://goo.gl/cE0gxz
• Source code - http://goo.gl/x1CVuc
Links to More Info
Editor's Notes
fun keyword
Return type – Unit
Types of args after names
Named arguments
Single expression functions
fun keyword
Return type – Unit
Types of args after names
Named arguments
Single expression functions
fun keyword
Return type – Unit
Types of args after names
Named arguments
Single expression functions
fun keyword
Return type – Unit
Types of args after names
Named arguments
Single expression functions
fun keyword
Return type – Unit
Types of args after names
Named arguments
Single expression functions
main.kt
application.kt
Takes a composer
Router.routeTo
Composable interface
ContainerComposer.kt
Router.kt
routeTo
Router (wrapped in clousure)
Controllable.kt
routeTo (reflection)
Example controllers