Kotlin Training Program

DOWNLOAD APP

FEEDBACK

Using APIs

In this module, we shall study about the Gradle build system and APIs including File I/O (reading and writing files), Date-Time and making HTTP requests programmatically.

What’s an API

API stands for Application Programming Interface. API is a way to reuse code, it provides an interface to perform certain tasks without knowing how they are performed under the hood.

Kotlin StdLib (Standard Library) provides the most basic APIs out of the box, such as Collections API including data structures like List, Map, Set etc. We can use them directly without knowing how they function internally. Example :

 fun main() {
		val list = listOf(1, 2, 3)
		println(list.reversed())
}
 

In the above program, we have used the built-in StdLib functions like listOf() and reversed() provided by the Collections API. It is not required to implement them or even know how they work. Implementation details are hidden that’s why API is called interface. APIs provide an interface i.e. set of files, classes, functions, etc. to be used as-is. For example, Kotlin Collections API provides set of classes like List, Map, Set and their functions to be used as-is. For this reason, API is also known as a Library.

Using APIs / Libraries this way, we can reuse the code written by other developers. Kotlin provides several other APIs like

We shall study File API in this module while others in later modules.

APIs

File I/O

Connecting to the Internet