Building an API with Kotlin and Ktor

in #utopian-io8 years ago (edited)

What Will I Learn?

  • You will learn how to use Ktor to build an API
  • You will learn how to model data and serve it through JSON in Kotlin
  • You will learn how to build HTML elements with Ktor

Requirements

  • The Kotlin Compiler or The Intellij/Eclipse IDE
  • A basic understanding of the JVM as a platform
  • A fair understanding of Kotlin or the Java programming language
  • A understanding of APIs and Web technologies

Difficulty

  • Intermediate

Description

In this Kotlin video tutorial, we look at how we can use the Ktor web framework to build concurrent RESTful APIs. We build out our data layer by creating a data class called Person. We also build a class to allow us to simulate a concurrent database. This database layer has the ability to add, remove and get the data objects from our data class.

We then use the Ktor framework to plugin various pieces of middle-ware that let modify the headers, add CORS and do various other functions to elements of our HTTP request and response cycle. We also use the Ktor Domain Specific Language (DSL) to build out how we want our API endpoint to route over the server. We make use of Dynamic Variables and co-routines to inlay our GET, DELETE and POST requests on various routes. We also take a look at the Ktor DSL that lets us build out HTML documents by building an index document for our application. Finally, we wire everything together in a way that would allow us to access this program from the command line.

The source code for this project can be found here

Video Tutorial

Related Content

  • Android Applications in Kotlin
  • Desktop Applications in Kotlin
  • Intro to Kotlin Series



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

That was very fast. Thank you for watching my content.

Hey @tensor I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.04
TRX 0.31
JST 0.087
BTC 58512.26
ETH 1565.93
USDT 1.00
SBD 0.38