Building an API with Kotlin and Ktor
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
- Intro to Kotlin (Basic Types, Type Inference, Casting and Strings)
- Intro to Kotlin (Basic Operations and Collections)
- Intro to Kotlin (Control Flow and Conditionals)
- Intro to Kotlin (Functions in Kotlin)
- Intro to Kotlin (Advanced Functions)
- Intro to Kotlin (Classes, Visibility Modifiers, Objects)
- Intro to Kotlin (Nullables, Data Classes, Enum Classes and Sealed Classes)
- Intro to Kotlin (Interfaces, Inheritance, Type Alias and Abstract Classes)
Posted on Utopian.io - Rewarding Open Source Contributors
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.
Wow its very useful.Upvote.
Hey @tensor I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
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