<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Mobile Studio India - Medium]]></title>
        <description><![CDATA[We are a digitally native company where innovation, design, and engineering meet scale. We use the latest technologies in the digital and cognitive fields to empower organizations in every aspect. - Medium]]></description>
        <link>https://medium.com/globant-mobile-studio-india?source=rss----de93816b048e---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Mobile Studio India - Medium</title>
            <link>https://medium.com/globant-mobile-studio-india?source=rss----de93816b048e---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 23:46:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/globant-mobile-studio-india" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Exploring server-side Kotlin using Ktor]]></title>
            <link>https://medium.com/globant-mobile-studio-india/exploring-server-side-kotlin-using-ktor-eb7d9432aeb1?source=rss----de93816b048e---4</link>
            <guid isPermaLink="false">https://medium.com/p/eb7d9432aeb1</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[ktor]]></category>
            <category><![CDATA[bekindkotlinchallenge]]></category>
            <dc:creator><![CDATA[Nikhil Jadhav]]></dc:creator>
            <pubDate>Wed, 15 Apr 2020 08:25:55 GMT</pubDate>
            <atom:updated>2020-04-15T08:25:55.001Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lk6rY2vriSEEYd-yoZ6wng.jpeg" /></figure><p>It its I/O 2017 developers conference May 17, Google announced Android is gaining official support for the <a href="https://googleweblight.com/i?u=https%3A%2F%2Fkotlinlang.org%2F&amp;hl=en-IN">Kotlin programming language</a>, in addition to Java and C++. Google describes Kotlin, which is an open-sourced project under the Apache 2.0 license, as “a brilliantly designed, mature language that we believe will make Android development faster and more fun.”</p><p>I am primarily an Android application developer &amp; thus the announcement changed a lot for me. However, In my experience, it turned out way cool to learn, especially for the people from compiled language background, as they can start writing code in Kotlin in no time. Also, we recently started experimenting Kotlin for building projects other than Android. We created an <a href="https://medium.com/@mukund.sharma/how-i-built-an-image-search-web-app-in-kotlin-js-994756c7ea5e">image-search web-app using Kotlin</a> entirely in no time.</p><p>We have a separate team for building APIs to be consumed by mobile + web platforms. That gave me an idea to experiment Kotlin for building APIs. So, the following are the findings-</p><p>The IDE will be IntelliJ built by Jetbrains. We will also be using <a href="https://ktor.io/">Ktor</a> framework.</p><p><a href="https://ktor.io/">Ktor</a> is an asynchronous web framework written in and designed for Kotlin. It gives us the ability to create client and server-side applications that can run and target multiple platforms while making use of the impressive features of Kotlin such as Coroutines.</p><p>You will have to install plugin <a href="https://ktor.io/quickstart/generator.html#">start.ktor.io</a> to create a Ktor project. On installation, you will be able to see a separate entry in the ‘Create New Project’ menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GBj3K7hRoSMzQJf1BrYeoA.png" /></figure><p>Without further ado, let&#39;s jump directly to creating APIs. This time we will work with the default settings.</p><p>Let’s finalise the project requirement first :D.</p><ul><li>It should have some in-memory database with pre-populated values</li><li>There should be API for fetching all records</li><li>There should be API for either create/update/delete of records in-memory database.</li></ul><h3>Declaring Dependencies</h3><p>The first step will be adding dependencies in the <em>build.gradle</em> file. Following are the extra additions that I did that were required for the functionality.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2fc35c43070d15419bbded244e050e5/href">https://medium.com/media/d2fc35c43070d15419bbded244e050e5/href</a></iframe><h3>Defining Model</h3><p>The first dependency <a href="https://github.com/JetBrains/Exposed">Exposed — Kotlin SQL Framework</a> which we will be using for creating an in-memory database.</p><p>The Ktor plugin creates basic files. Let’s define a table to work within our project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e791bd29a026e36bb2c52c61d699d5e/href">https://medium.com/media/9e791bd29a026e36bb2c52c61d699d5e/href</a></iframe><p>As you can see, now we have defined a table called <em>“user” </em>with 3 columns.</p><h3>Initialising Database and Operations</h3><p>Now we need to initialise the database and prefill some rows in the User table. Following is the code snippet that we will be using to init and prefill the User table.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f88d0b607f3df07cd9784edd12f74057/href">https://medium.com/media/f88d0b607f3df07cd9784edd12f74057/href</a></iframe><p>The above code will create an in-memory DB with table named User and will pre-fill some data so that we can work on creating some APIs on the table.</p><p>Let&#39;s check the code-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ac833dcb56c205bba2d178837c67c1f/href">https://medium.com/media/1ac833dcb56c205bba2d178837c67c1f/href</a></iframe><p>The above code snippet runs <em>SELECT </em>query on the database and returns the result in JSON formatted manner by making use of GSON library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d653e4bf04762bf6660f3034dd5368e4/href">https://medium.com/media/d653e4bf04762bf6660f3034dd5368e4/href</a></iframe><p>The above code snippet is for <em>DELETE</em> operation on the in-memory DB that we have. Now, let&#39;s jump into code which defines API using which we will be able to make changes to the database.</p><h3>Defining Routes</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67fb73e475c21cef99c207528c94d948/href">https://medium.com/media/67fb73e475c21cef99c207528c94d948/href</a></iframe><p>As we know that internally all Kotlin code compiles to JVM code. So, it will definitely have the <strong><em>main</em></strong> function which kickstarts the application. Here, in the above snippet, we have the <strong><em>main </em></strong>function. It first does the initialising of DB &amp; starts a server using Netty client-server framework on port 8080. It also defines various routes exposed to be consumed by different platforms. Here, I have defined 3 routes</p><ul><li>First one: the default and was used for debugging. It returned text “Hello” when hit.</li><li>Second one: This API makes use of the function to get all records from DB and return it in JSON format.</li><li>Third one: This API accepted a parameter which was passed to the function. The function deleted any records in table User which matched the value of field <em>name</em> with the given parameter. It also returned text “true” or “false” depending on if the record was deleted or not.</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxT9IggDCSIWH5jcOdy%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FxT9IggDCSIWH5jcOdy%2Fsource.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FxT9IggDCSIWH5jcOdy%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e9ef245d632d869e7f2fba4e5ed2139/href">https://medium.com/media/6e9ef245d632d869e7f2fba4e5ed2139/href</a></iframe><p>That’s it, people. We will require to just run the application and we will be able to access the APIs (in this case we can test in browser as we have defined GET methods).</p><p><strong><em>What motivated me to share my experience</em></strong></p><p>I always thought API implementation a tedious process which involved a lot of steps. I always assumed creating REST APIs took a lot of time as it has a lot of things to be taken care of before one can start consuming the APIs. With Kotlin and well-built framework — Ktor <a href="https://monkey.org/~marius/funsrv.pdf">implementing server is now as easy as writing a function</a>.</p><p>To be fair, it just took some reading and learning to accomplish the POC in a <strong>few hours</strong>. That includes exploration and implementation (&amp; writing this blog as well :P). You will be able to accomplish more and utilise time efficiently.</p><p>Also, <a href="https://ktor.io/">Ktor</a> is built by <a href="https://www.jetbrains.com/">Jetbrains</a> aka the guys who built <strong><em>Kotlin</em></strong> &amp; also the powerful IDE — <strong><em>IntelliJ</em></strong>. What we learned was just a tiny little part from the huge functionality that Ktor provides. <em>Happy Coding</em> :)</p><h3>#BeKindKotlinChallenge</h3><blockquote><em>Inspired by Kotlin, we’ve launched a coding contest powered by </em><a href="https://www.globant.com/"><em>Globant </em></a><em>and </em><a href="https://www.jetbrains.com/"><em>Jetbrains</em></a><em>.</em></blockquote><blockquote><a href="http://uiorbit.globant.com/"><em>Click here</em></a><em> to know more!</em></blockquote><p>Team Credits: <a href="https://medium.com/u/733fa45e5564?source=post_page-----d9cbcfba34a2----------------------">Mukund</a> | <a href="https://medium.com/u/fca6492380a9?source=post_page-----994756c7ea5e----------------------">Sumit Sutar</a>| <a href="https://medium.com/u/bb9487b17334?source=post_page-----d9cbcfba34a2----------------------">Akshata Shelar</a> | <a href="https://medium.com/u/ddb5232e0b42?source=post_page-----d9cbcfba34a2----------------------">Archana</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb7d9432aeb1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/globant-mobile-studio-india/exploring-server-side-kotlin-using-ktor-eb7d9432aeb1">Exploring server-side Kotlin using Ktor</a> was originally published in <a href="https://medium.com/globant-mobile-studio-india">Mobile Studio India</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>