Save 37% off PRO during our Black Friday Sale! »

Backend Engineering for Android Developers

Backend Engineering for Android Developers

With Kotlin growing in popularity, it's about time we start looking at Kotlin as a language that has superpowers.
When we talk about backend technologies, we have a lot of languages/frameworks like Go, Java, Python, etc.
But when we talk about Kotlin as a backend language, it might raise a lot of eyebrows
But let me try to convince you that Kotlin is definitely a good choice for Backend! We will talk about Ktor (A framework for Kotlin) to build a fast backend that can be re-used on your client-side

4371065e0b25abc81550754e316fb26e?s=128

Himanshu Singh

October 22, 2021
Tweet

Transcript

  1. Backend for Android Engineers

  2. 01. About me

  3. 3 Himanshu Singh Android @Clue, GDE - Android,Kotlin

  4. 4 Agenda: Backend for Android Engineers 01. Intro Kotlin Android?

    Backend Benefits 02. Kotlin Frameworks Ktor Spring Boot Vertx. Etc. 03. Ktor Why? How? Benefits 04. Tutorial Setting up Restful APIs Routing HTTP Verbs Features Location Status Pages 05. Why to use as Android Developer?
  5. 01. Introduction

  6. 6 Introduction 01. Kotlin?

  7. 7 Introduction 01. Kotlin? Android?

  8. 8 Introduction 01. Kotlin? Android? Backend

  9. Benefits 1. 2. 3. 4. 5. Expressive Tooling Migration 6.

    Scalable! Community Support Ease of Learning
  10. 02. Frameworks

  11. Frameworks 1. 2. 3. 4. 5. Ktor Micronauts Vertx Spring

    Boot A lot more!
  12. 03. Ktor

  13. 13  Ktor Why?

  14. Ktor 1. 2. 3. 4. 5. Light weighted Backed by

    Jetbrains Coroutine support Open sourced Scalable -> ∞
  15. 04. Tutorial.

  16. 16  Tutorial: Web https://start.ktor.io/

  17. 17  Tutorial: Web

  18. 18  Tutorial: Web Create Project

  19. 19  Tutorial: Web Create Project

  20. 20  Tutorial: Output

  21. Code run through!

  22. 22  fun main() { embeddedServer(Netty, port = 8080, host

    = "0.0.0.0") { configureRouting() }.start(wait = true) }
  23. 23  fun main() { embeddedServer(Netty, port = 8080, host

    = "0.0.0.0") { configureRouting() }.start(wait = true) }
  24. 24  fun main() { embeddedServer(Netty, port = 8080, host

    = "0.0.0.0") { configureRouting() }.start(wait = true) }
  25. 05. Routing

  26. 26  fun Application.configureRouting() { // Starting point for a

    Ktor app: routing { get("/") { call.respondText("Hello World!") } } }
  27. 27  fun Application.configureRouting() { // Starting point for a

    Ktor app: routing { get("/") { call.respondText("Hello World!") } } }
  28. 28  fun Application.configureRouting() { // Starting point for a

    Ktor app: routing { get("/") { call.respondText("Hello World!") } } }
  29. 29  fun Application.configureRouting() { // Starting point for a

    Ktor app: routing { get("/") { call.respondText("Hello World!") } } }
  30. 30  fun Application.configureRouting() { // Starting point for a

    Ktor app: routing { get("/") { call.respondText("Hello World!") } } }
  31. HTTP Verbs

  32. HTTP Verbs 1. 2. 3. 4. GET PUT/PATCH DELETE POST

  33. 33  routing { get("/") { //code } post("/") {

    //code } delete("/") { //code } put("/") { //code } }
  34. 06. Plugins

  35. “ Set of pre-coded packages to help you ship/build faster

  36. 36  fun Application.dummyPlugin(){ install(//the plugin) }

  37. 37  fun main() { embeddedServer(Netty, port = 8080, host

    = "0.0.0.0") { configureRouting() dummyPlugin() }.start(wait = true) }
  38. 38  fun Application.contentNegotiation(){ install(ConentNegotiation){ gson() } }

  39. 07. Real world example.

  40. 40  fun Application.configureRouting(){ post("/create-user"){ val user = call.receive<User>() //create

    user call.respond(user) } }
  41. 41  fun Application.configureRouting(){ post("/create-user"){ val user = call.receive<User>() //create

    user call.respond(user) } }
  42. 42  { "name":"Himanshu", "age":26, "job":"Clue" } data class User(

    val name:String, val age:Int, val job:String )
  43. 43  https://www.google.com/search?q=droidcon+berlin

  44. 44  https://www.google.com/search?q=droidcon+berlin

  45. 45  fun Application.configureRouting(){ get("/search"){ val param = call.request.queryParameters[“q”] //code

    call.respond(result) } }
  46. 08. Locations

  47. “ A mechanism to create routes in a typed way,

    for both: constructing URLs and reading the parameters.
  48. 48  fun Application.module() { install(Locations) // ... }

  49. 49  @Location("/list/{name}/page/{page}") data class Listing(val name: String, val page:

    Int)
  50. 50  routing { get<Listing> { listing -> call.respondText("Listing ${listing.name},

    page ${listing.page}") } }
  51. 09. Status Page

  52. “ Response to any failure state/Exception.

  53. 53  fun Application.module() { install(StatusPages) // ... }

  54. 54  install(StatusPages) { exception<AuthenticationException> { cause -> call.respond(HttpStatusCode.Unauthorized) }

    exception<AuthorizationException> { cause -> call.respond(HttpStatusCode.Forbidden) } }
  55. 10. Libraries Available for Awesomeness

  56. Why? 1. 2. 3. 4. 5. KMongo/Expose In build Authentication/Auth

    Velocity / Kotlin HTML Gson/Jackson Swagger, ORM etc.
  57. 10. Why use it as android Dev?

  58. Why? 1. 2. 3. 4. 5. Uses our fav. Kotlin

    KMM support Easy learning curve. Supports JVM Libraries Makes you a full stack developer.
  59. 11. Summary

  60. Summary 1. 2. Use Kotlin to do anything Build your

    own backend
  61. 12. Resources

  62. 62  Resources https://ktor.io/ https://himanshoe.com

  63. Danke Schön! Questions?