0Pricing
Kotlin Multiplatform Academy · Ders

API'yi Deponun Ardında Sarmalama

Ktor'u ve serileştirmeyi çağıranlardan gizleyin.

API'yi Deponun Ardında Sarmalama, CoddyKit'te ücretsiz bir Kotlin Multiplatform Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Kotlin Multiplatform Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Kotlin Multiplatform Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Now Build the Real Thing

With the interface set, you write a concrete implementation that actually fetches data behind the scenes.

Implement the Interface

Create a class that uses implements the repository interface, promising to fulfill every method it declares.

class UserRepositoryImpl : UserRepository

Inject the Ktor Client

Pass the HttpClient into the constructor instead of creating it inside, so it can be shared and replaced in tests.

class UserRepositoryImpl(private val client: HttpClient) : UserRepository

Hide the Network Call

Inside each method, make the Ktor request and return the result. Callers see clean data, never the request itself.

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

Keep URLs Inside

Store base URLs and paths within the implementation. The rest of the app stays blissfully unaware of any endpoint.

One Place to Change

If the API path changes, you edit only this class. The interface and every caller stay untouched.

Serialization Stays Hidden

The body call turns JSON into models here, so serialization never leaks out to the UI layer.

val user: User = client.get(url).body()

Same Code, Both Apps

This implementation lives in commonMain, so the same fetching code powers Android and iOS identically.

Swap Without Breaking Callers

Because it satisfies the interface, you can replace it with a caching version later and no caller changes.

Wire It With DI

A dependency injection setup hands callers this implementation through the interface type, keeping things loosely coupled.

single<UserRepository> { UserRepositoryImpl(get()) }

The Full Wrapper

Here is the complete wrapper: it takes a client, hides the request, and returns plain domain models.

class UserRepositoryImpl(
    private val client: HttpClient
) : UserRepository {
    override suspend fun getUsers() =
        client.get("/users").body<List<User>>()
}

Quick Check

What is the main job of the repository implementation?

Recap

The implementation takes an HttpClient, performs the request, and returns domain models, keeping all networking sealed off from callers.

Sıkça Sorulan Sorular

“API'yi Deponun Ardında Sarmalama” dersi ücretsiz mi?

Evet — “API'yi Deponun Ardında Sarmalama” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Kotlin Multiplatform Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Kotlin Multiplatform Academy kursu toplamda 4 dersten oluşur.

“API'yi Deponun Ardında Sarmalama” dersinde ne öğreneceğim?

Ktor'u ve serileştirmeyi çağıranlardan gizleyin. Kotlin Multiplatform Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Kotlin Multiplatform Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Kotlin Multiplatform Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.

“API'yi Deponun Ardında Sarmalama” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Kotlin Multiplatform Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Kotlin Multiplatform Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Bir Depo Arayüzü Tanımlama
  2. API'yi Deponun Ardında Sarmalama
  3. DTO'ları Alan Modellerine Eşleme
  4. Sonuçları Flow Olarak Dışa Açma
← Kotlin Multiplatform Academy Sayfasına Dön