0Pricing
Kotlin Multiplatform Academy · Lesson

Your First GET Request

Fetch JSON from an API in shared code.

Your First GET Request is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Fetch From Shared Code

With the client ready, you can now make your first GET request from commonMain and reuse it on both apps. 🚀

Network Calls Suspend

Every Ktor request is a suspend function, so it never blocks a thread and fits naturally into coroutines.

suspend fun load() { /* request here */ }

Call get With a URL

The simplest request passes a URL string to client.get, which returns an HttpResponse you can read from.

val response = client.get("https://api.example.com/users")

Read the Status Code

Check whether the call succeeded by reading response.status before you trust the body.

if (response.status.value == 200) { /* ok */ }

Get the Body as Text

To read the payload, call bodyAsText, which suspends and returns the raw response as a String.

val json: String = response.bodyAsText()

Typed Bodies Are Cleaner

Ktor can deserialize directly into a type using body, saving you from parsing the text by hand later.

val users: List<User> = response.body()

One-Line GET

You can also skip the response object entirely and let get return your typed result in a single expression.

val users: List<User> = client.get(url).body()

Wrap in a Function

Put the call inside a clean suspend function so both apps share the exact same fetching logic.

suspend fun fetchUsers() = client.get(url).body<List<User>>()

Run It From a Scope

Because the call suspends, you launch it inside a coroutine scope rather than calling it from plain synchronous code.

scope.launch { val users = fetchUsers() }

It Works on Both Apps

This single function now runs on Android and iOS with no changes, because the engine differences live below the API.

Keep Calls in the Repository

For real apps, hide raw get calls inside a repository so the UI never touches Ktor directly.

Quick Check

How do you read the raw response payload as a String?

Recap

A GET request is a suspend call: get the URL, check status, then read the body as text or a typed object. One function serves both apps.

Frequently asked questions

Is the “Your First GET Request” lesson free?

Yes — the full text of “Your First GET Request” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.

What will I learn in “Your First GET Request”?

Fetch JSON from an API in shared code. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Kotlin Multiplatform Academy?

No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Your First GET Request” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Kotlin Multiplatform Academy lesson?

Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Add Ktor & Pick Platform Engines
  2. Your First GET Request
  3. POST, Headers & Query Params
  4. Timeouts, Logging & Base URLs
← Back to Kotlin Multiplatform Academy