Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin Server Side development

C439538cf5661049a0d6ff610681c3d7?s=47 Nevin
October 04, 2019

Kotlin Server Side development

The same talk was given in Android Taipei 2019-9-24
This slide is updated for JCConf 2019 on 2019-10-4

C439538cf5661049a0d6ff610681c3d7?s=128

Nevin

October 04, 2019
Tweet

Transcript

  1. Kotlin Server-Side Development Using Ktor @chennevin

  2. Agenda •Ktor •Android -> Backend

  3. Ktor • Easy to Learn • Easy to Use •

    Client + Server • Features / Middleware • OAuth 2 - Firefox Account • Nice Architecture • Routing + Controller
  4. None
  5. start.ktor.io

  6. start.ktor.io

  7. None
  8. Intellij Plugin

  9. Auto Sync….

  10. None
  11. My First Server

  12. Respond Text

  13. Respond… JSON?

  14. Content Negotiation

  15. Content Negotiation

  16. None
  17. Getting Parameters

  18. Features (Middleware)

  19. Firefox Account • Internal only— Coming soon! API DOC •

    OAuth 2.0 (authentication grand type) • authorization • token • profile
  20. Ktor Auth (Oauth)

  21. Ktor Auth (Oauth)

  22. Retrofit :)

  23. Architecture (MVC) • RSS API

  24. Architecture (Route)
 https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/routes •

  25. Route VS Controller

  26. Routing HelloRoute.kt

  27. Google App Engine • Build highly scalable applications on a

    fully managed serverless platform • Java 8 + Jetty9 • Java 11 (Beta)+Netty • Sample: Mobile app backend services
  28. Google App Engine • Build highly scalable applications on a

    fully managed serverless platform • Java 8 + Jetty9 • Java 11 (Beta)+Netty • Sample: Mobile app backend services
  29. Ktor on App Engine • Follow the document Follow Ktor

    Doc
  30. Add GAE Manually(1)

  31. Add GAE Manually(2)

  32. Ktor Good Read • Mobile Backends (IO 2019)
 https://www.youtube.com/watch? v=zjWOMBdPbsI&t=517s

    • KotlinConf Ryan Harter 
 https://www.youtube.com/watch?v=V4PS3IjIzlw
  33. Exception Handling[link]

  34. • Don’t make exception a part of your business logic

    • Don’t abuse GlobalExceptionHandler • Use standard Exception • Kotlin doesn’t have checked exception • Cleaner code • Need to look into library method that throws Exception Handling[link]
  35. Exception Handling • Don’t make exception a part of your

    business logic • Don’t abuse GlobalExceptionHandler • Use standard Exception • Kotlin doesn’t have checked exception • Cleaner code • Need to look into library method that throws
  36. (Android Dev)->Backend Dev Diff Same RAM IoC Async Testing Killed

    Application Context Error
  37. Annotation Use-site Targets •

  38. None
  39. Armeria • HTTP/2 RPC/REST client/ server library • built on

    top of Java 8, Netty, Thrift and gRPC https://www.youtube.com/ watch?v=hLlctum1pIA
  40. None
  41. None
  42. None
  43. None
  44. None
  45. None
  46. None
  47. None
  48. None
  49. None
  50. None
  51. None
  52. Ktor Route Creation • Extension functions

  53. Ktor Route Creation • Extension

  54. Ktor Route Creation • Extension Configure

  55. Spring Controller Creation

  56. Spring Handling Request

  57. Ktor Handling Request

  58. Take away • Ktor • Introduction • Request / Respond

    • Features • Firefox Account • Architecture • Deploy to Google App Engine • Backend development for Android dev • Exception Handling • Annotation Use-site Targets • Final / Nullable • Spring / Armeria / Ktor
  59. Suggestions… • Use Ktor GAE samples • Use Groovy Gradle

    build script for now • Be careful fo Intellij 2019.2 (don’t touch offline mode!)
  60. Thank you! @chennevin