{"slug":"kmp-api-endpoint","title":"kmp-api-endpoint","summary":"Use when adding, wiring or fixing one REST endpoint in a Kotlin Multiplatform shared module — \"add a GET/POST/PUT/DELETE call\", \"integrate this API\", \"call /orders from shared code\", an OTP or token endpoint — covering the Ktor request, @Serializable DTOs, mapper, repository, use","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-12-03T17:29:48.567653Z","repo":{"url":"https://github.com/Kushpawan/kmp-mobile-skills","stars":17,"forks":2,"license":"Apache-2.0","updatedAt":"2026-12-03T13:18:24Z"},"bodyHtml":"<hr>\n<h2>name: kmp-api-endpoint\ndescription: Use when adding, wiring or fixing one REST endpoint in a Kotlin Multiplatform shared module — \"add a GET/POST/PUT/DELETE call\", \"integrate this API\", \"call /orders from shared code\", an OTP or token endpoint — covering the Ktor request, @Serializable DTOs, mapper, repository, use case, Koin wiring and MockEngine tests, or when a new endpoint fails with MissingFieldException or JsonDecodingException, returns 404 because of a wrong path, or works on Android but not iOS.\nlicense: Apache-2.0\ncompatibility: Kotlin Multiplatform project (Android + iOS) with Ktor client 3.x (3.6 current) and kotlinx.serialization 1.7+ (1.13 current). iOS test runs need macOS with Xcode.\nmetadata:\ncategory: data\nplatforms: android, ios</h2>\n<h1>Add one REST endpoint to a KMP app</h1>\n<p>A concrete recipe: one endpoint, from wire contract to tested repository, in the project's own shape.\nThe architecture behind each step — untrusted DTOs, one shared client, typed errors — is in\n<strong>kmp-data-layer</strong>; this skill applies it file by file.</p>\n<h2>When to use</h2>\n<ul>\n<li>Adding a new GET, POST, PUT, PATCH or DELETE call to shared code.</li>\n<li>Adding a method to an existing API service, repository and use case.</li>\n<li>Fixing a freshly added endpoint: parse failures, wrong URL, missing auth header, untested errors.</li>\n</ul>\n<h2>When not to use</h2>\n<ul>\n<li>Designing the data layer, HttpClient, auth refresh or result type from scratch — use <strong>kmp-data-layer</strong> first.</li>\n<li>Caching the response in a database or syncing offline writes — <strong>kmp-data-layer</strong> (offline-first) and <strong>kmp-room-database</strong>.</li>\n<li>DI start-up problems (<code>NoDefinitionFoundException</code> at launch) — <strong>kmp-koin-di</strong>.</li>\n</ul>\n<h2>Inputs — get these before writing code</h2>\n<table>\n<thead>\n<tr>\n<th>Input</th>\n<th>Example</th>\n<th>If missing</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Method and path</td>\n<td><code>GET orders/{orderId}</code></td>\n<td>Ask.</td>\n</tr>\n<tr>\n<td>Path and query parameters</td>\n<td><code>orderId: String</code>, <code>?expand=items</code></td>\n<td>Ask which are optional.</td>\n</tr>\n<tr>\n<td>Request body sample</td>\n<td>JSON</td>\n<td>Required for POST/PUT/PATCH.</td>\n</tr>\n<tr>\n<td>Response sample</td>\n<td>Real JSON, ideally from the API docs or a recorded call</td>\n<td><strong>Ask. Never invent field names.</strong></td>\n</tr>\n<tr>\n<td>Error statuses</td>\n<td>404 unknown id, 409 already cancelled</td>\n<td>Use the defaults in the error mapping.</td>\n</tr>\n<tr>\n<td>Auth</td>\n<td>bearer / none</td>\n<td>Picks the authenticated or plain client.</td>\n</tr>\n<tr>\n<td>Pagination</td>\n<td>cursor / page+size / none</td>\n<td>Shapes the domain return type.</td>\n</tr>\n</tbody>\n</table>\n<h2>Step 0 — Read the project first</h2>\n<ol>\n<li><strong>Find the closest existing endpoint and copy its shape.</strong>\n<pre><code>grep -rln \"client.get\\|client.post\\|HttpClient\" --include=*.kt */src/commonMain | head\n</code></pre>\nOpen one complete vertical (API → repository → use case → DI → tests). Note package layout, file\nnames, the <code>toDomain()</code> style, whether use cases exist, and how tests are written.</li>\n<li><strong>Detect the building blocks</strong> — reuse each one, never add a parallel version:\n<pre><code>grep -rnE \"sealed (class|interface) [A-Za-z]*(Result|Outcome)\" --include=*.kt .    # result type\ngrep -rnE \"suspend fun &lt;T&gt; [A-Za-z]*(Call|Request)\" --include=*.kt .               # error-boundary helper\ngrep -rn \"named(\" --include=*.kt . | grep -i client                                 # client qualifiers\ngrep -rnE \"DispatcherProvider|MockEngine|class Fake\" --include=*.kt . | head -20    # dispatchers, test helpers\n</code></pre>\n</li>\n<li><strong>Check whether files already exist.</strong> If <code>OrdersApi</code> exists, add a method; don't create <code>OrdersApi2</code>.</li>\n<li><strong>Read the library versions</strong> — they decide which pitfalls in <strong>Version notes</strong> apply:\n<pre><code>grep -nE \"ktor|serialization|datetime|coroutines\" gradle/libs.versions.toml\n</code></pre>\n</li>\n</ol>\n<p>If the project has none of this, set up the data layer with <strong>kmp-data-layer</strong> first. The examples\nbelow use its defaults: <code>ApiResult</code> / <code>DataError</code>, <code>safeApiCall</code>, <code>DispatcherProvider</code>, Koin with\n<code>named(\"authenticated\")</code>, package <code>com.example.app</code>.</p>\n<h2>Workflow</h2>\n<p>Example endpoint: <code>GET orders/{orderId}</code> → one order with line items.</p>\n<h3>1. Response DTOs — <code>orders/data/remote/dto/OrderDto.kt</code></h3>\n<pre><code>@Serializable\ndata class OrderDto(\n    @SerialName(\"id\") val id: String? = null,\n    @SerialName(\"status\") val status: String? = null,\n    @SerialName(\"total_minor\") val totalMinor: Long? = null,\n    @SerialName(\"currency\") val currency: String? = null,\n    @SerialName(\"placed_at\") val placedAtEpochMillis: Long? = null,\n    @SerialName(\"items\") val items: List&lt;OrderItemDto&gt;? = null,\n)\n\n@Serializable\ndata class OrderItemDto(\n    @SerialName(\"sku\") val sku: String? = null,\n    @SerialName(\"name\") val name: String? = null,\n    @SerialName(\"quantity\") val quantity: Int? = null,\n)\n</code></pre>\n<p>Every response field nullable, <code>= null</code>, explicit <code>@SerialName</code>. Enums arrive as <code>String?</code>.\nRequest DTOs (for POST/PUT) may be non-null. Done when the DTO round-trips the sample JSON in a test.</p>\n<ul>\n<li><strong>Timestamps and ids.</strong> An ISO-8601 string can decode straight into <code>kotlin.time.Instant?</code> and a\nUUID string into <code>kotlin.uuid.Uuid?</code> — both serializers are stable since kotlinx.serialization\n1.12.0 — but one malformed value then fails the whole response. Unless the API guarantees the\nformat, keep <code>String?</code> and parse in the mapper. Epoch numbers stay <code>Long?</code> (as <code>placed_at</code> here).\nNever add the deprecated <code>kotlinx.datetime.Instant</code>.</li>\n<li><strong>No validation in DTOs</strong> (<code>init { require(...) }</code>, custom serializers that throw): the exception\nclass it produces differs between kotlinx.serialization 1.12.x and 1.13.0. Validate in the mapper.</li>\n</ul>\n<h3>2. Domain model — <code>orders/domain/Order.kt</code></h3>\n<pre><code>data class Order(\n    val id: String,\n    val status: OrderStatus,\n    val total: Money,\n    val placedAtEpochMillis: Long,\n    val items: List&lt;OrderItem&gt;,\n)\n\ndata class Money(val amountMinor: Long, val currency: String)\ndata class OrderItem(val sku: String, val name: String, val quantity: Int)\nenum class OrderStatus { Pending, Shipped, Delivered, Cancelled, Unknown }\n</code></pre>\n<p>Plain, non-null, no annotations. Money as minor units plus currency, never <code>Double</code>.</p>\n<h3>3. Mapper — <code>orders/data/OrderMappers.kt</code></h3>\n<pre><code>internal fun OrderDto.toDomainOrNull(): Order? {\n    val id = id?.takeIf { it.isNotBlank() } ?: return null\n    val amount = totalMinor ?: return null            // never default money to 0\n    val currency = currency?.takeIf { it.length == 3 } ?: return null\n    return Order(\n        id = id,\n        status = status.toOrderStatus(),\n        total = Money(amountMinor = amount, currency = currency.uppercase()),\n        placedAtEpochMillis = placedAtEpochMillis ?: 0L,\n        items = items.orEmpty().mapNotNull { it.toDomainOrNull() },\n    )\n}\n\ninternal fun OrderItemDto.toDomainOrNull(): OrderItem? {\n    val sku = sku?.takeIf { it.isNotBlank() } ?: return null\n    val quantity = quantity?.takeIf { it &gt; 0 } ?: return null\n    return OrderItem(sku = sku, name = name.orEmpty(), quantity = quantity)\n}\n\nprivate fun String?.toOrderStatus(): OrderStatus = when (this?.lowercase()) {\n    \"pending\" -&gt; OrderStatus.Pending\n    \"shipped\" -&gt; OrderStatus.Shipped\n    \"delivered\" -&gt; OrderStatus.Delivered\n    \"cancelled\" -&gt; OrderStatus.Cancelled\n    else -&gt; OrderStatus.Unknown                       // new server values must not crash old apps\n}\n</code></pre>\n<p>List each field as <strong>required</strong> (drop or fail) or <strong>cosmetic</strong> (fall back). Each rule gets a test.</p>\n<h3>4. API service — <code>orders/data/remote/OrdersApi.kt</code></h3>\n<pre><code>interface OrdersApi {\n    suspend fun getOrder(orderId: String): OrderDto\n}\n\ninternal class KtorOrdersApi(private val client: HttpClient) : OrdersApi {\n    override suspend fun getOrder(orderId: String): OrderDto =\n        client.get(\"orders/${orderId.encodeURLPathPart()}\").body()\n}\n</code></pre>\n<ul>\n<li>Relative path, no leading <code>/</code> — it resolves against the client's base URL.</li>\n<li><strong>Encode path parameters.</strong> <code>encodeURLPathPart()</code> (from <code>io.ktor.http</code>) escapes <code>/</code>, <code>?</code> and <code>#</code>;\nraw interpolation lets an id like <code>../admin</code> or <code>a?b=c</code> change the request.</li>\n<li>No <code>try</code>/<code>catch</code>, no mapping, no headers the shared client already adds.</li>\n</ul>\n<h3>5. Repository — <code>orders/domain/OrdersRepository.kt</code> + <code>orders/data/OrdersRepositoryImpl.kt</code></h3>\n<pre><code>interface OrdersRepository {\n    suspend fun getOrder(orderId: String): ApiResult&lt;Order&gt;\n}\n\nclass OrdersRepositoryImpl(\n    private val ordersApi: OrdersApi,\n    private val dispatchers: DispatcherProvider,\n) : OrdersRepository {\n\n    override suspend fun getOrder(orderId: String): ApiResult&lt;Order&gt; =\n        safeApiCall(dispatchers.default) {\n            ordersApi.getOrder(orderId).toDomainOrNull()\n                ?: throw SerializationException(\"Order response is missing required fields\")\n        }\n}\n</code></pre>\n<p>The error boundary maps HTTP status, transport and parse failures to <code>DataError</code> and rethrows\ncancellation. An order missing required fields becomes <code>DataError.Serialization</code>, not a crash and\nnot a half-empty screen.</p>\n<h3>6. Use case — only if the project uses them</h3>\n<pre><code>// orders/domain/GetOrderUseCase.kt\nclass GetOrderUseCase(private val ordersRepository: OrdersRepository) {\n    suspend operator fun invoke(orderId: String): ApiResult&lt;Order&gt; {\n        if (orderId.isBlank()) return ApiResult.Failure(DataError.Validation(serverMessage = null))\n        return ordersRepository.getOrder(orderId)\n    }\n}\n</code></pre>\n<p>If the project's ViewModels call repositories directly, skip this file — a pass-through use case\nadds a layer and tests nothing.</p>\n<h3>7. DI — <code>orders/di/OrdersModule.kt</code></h3>\n<pre><code>val ordersModule = module {\n    single&lt;OrdersApi&gt; { KtorOrdersApi(client = get(named(\"authenticated\"))) }\n    single&lt;OrdersRepository&gt; { OrdersRepositoryImpl(ordersApi = get(), dispatchers = get()) }\n    factoryOf(::GetOrderUseCase)\n}\n</code></pre>\n<p>Add <code>ordersModule</code> to the app's module list (or the feature aggregator's <code>includes(...)</code>). Use the\nplain client for endpoints that must not carry a token. Done when the DI verification test passes\n(see <strong>kmp-koin-di</strong>) or the app starts and resolves the screen's ViewModel.</p>\n<h3>8. Tests — <code>commonTest/.../orders/</code></h3>\n<p>Write these four, using the templates in <a href=\"references/test-templates.md\">references/test-templates.md</a>:</p>\n<table>\n<thead>\n<tr>\n<th>File</th>\n<th>Covers</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>OrderMapperTest</code></td>\n<td>every required-field drop, every fallback, unknown enum value</td>\n</tr>\n<tr>\n<td><code>KtorOrdersApiTest</code></td>\n<td>method, encoded path, query, headers, body; parses the sample JSON through the real client</td>\n</tr>\n<tr>\n<td><code>OrdersRepositoryImplTest</code></td>\n<td>success; 404 → <code>NotFound</code>; 401 → <code>Unauthorized</code>; malformed body → <code>Serialization</code>; offline → <code>NoConnection</code></td>\n</tr>\n<tr>\n<td><code>FakeOrdersRepository</code></td>\n<td>a fake for ViewModel and use-case tests (not a test itself)</td>\n</tr>\n</tbody>\n</table>\n<p>Name tests <code>should_&lt;expected&gt;_when_&lt;condition&gt;</code> unless the project uses another convention.</p>\n<h3>9. Run the checks in <strong>Verify</strong>.</h3>\n<h2>Variations</h2>\n<table>\n<thead>\n<tr>\n<th>Need</th>\n<th>Do this</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Query parameters</td>\n<td><code>client.get(\"orders\") { parameter(\"status\", status) }</code> — a <code>null</code> value is skipped</td>\n</tr>\n<tr>\n<td>Repeated query key</td>\n<td><code>client.get(\"orders\") { url { parameters.appendAll(\"tag\", tags) } }</code></td>\n</tr>\n<tr>\n<td>POST with JSON body</td>\n<td><code>client.post(\"orders\") { contentType(ContentType.Application.Json); setBody(CreateOrderRequest(...)) }</code></td>\n</tr>\n<tr>\n<td>PATCH (partial update)</td>\n<td>Request DTO with only the changed fields. With <code>explicitNulls = false</code> a <code>null</code> is <strong>omitted</strong>, so \"clear this field\" needs an explicit design (a <code>JsonObject</code> body or a dedicated flag)</td>\n</tr>\n<tr>\n<td>204 No Content</td>\n<td><code>client.delete(\"orders/${id.encodeURLPathPart()}\")</code> and return <code>Unit</code>; do not call <code>.body()</code></td>\n</tr>\n<tr>\n<td>Pagination</td>\n<td>DTO carries <code>next_cursor</code>; domain returns <code>Page&lt;Order&gt;(items, nextCursor)</code>; the ViewModel owns \"load more\"</td>\n</tr>\n<tr>\n<td>Multipart upload</td>\n<td><code>client.submitFormWithBinaryData(url = \"uploads\", formData = formData { append(\"file\", bytes, Headers.build { append(HttpHeaders.ContentDisposition, \"filename=\\\"receipt.jpg\\\"\") }) }) { timeout { requestTimeoutMillis = 120_000 } }</code></td>\n</tr>\n<tr>\n<td>Pre-signed upload URL (third-party host)</td>\n<td>Absolute URL through a client <strong>without</strong> the bearer provider, or a bearer config whose <code>sendWithoutRequest</code> excludes that host</td>\n</tr>\n<tr>\n<td>Retry-safe create</td>\n<td>If the backend supports it, send a client-generated idempotency key header so a retried POST does not create a duplicate</td>\n</tr>\n<tr>\n<td>Response wrapped in an envelope</td>\n<td><code>{\"data\": {...}}</code> → an <code>EnvelopeDto&lt;T&gt;(@SerialName(\"data\") val data: T? = null)</code>; unwrap in the mapper</td>\n</tr>\n<tr>\n<td>Token endpoint needing its own <code>Authorization</code> (Basic client credentials)</td>\n<td>Call it through the plain client. With <code>markAsRefreshTokenRequest()</code> on the authenticated client, Ktor before 3.6.0 strips that header (see <strong>Version notes</strong>)</td>\n</tr>\n<tr>\n<td>SMS OTP send / verify</td>\n<td>The endpoints are ordinary POSTs; reading the code is platform UI. See <strong>OTP endpoints and Android 17</strong></td>\n</tr>\n</tbody>\n</table>\n<h2>OTP endpoints and Android 17</h2>\n<p>Android 17 delays SMS one-time codes by three hours for apps that are not their intended reader:\nstandard-format OTP SMS for most apps targeting API 37, and WebOTP- or SMS Retriever-format\nmessages for every app that is not the verified recipient. During the delay the\n<code>SMS_RECEIVED_ACTION</code> broadcast is withheld and SMS provider queries are filtered. An app that\nreads the inbox (<code>READ_SMS</code> / <code>RECEIVE_SMS</code>) to auto-fill the code gets it three hours late.</p>\n<ul>\n<li><strong>Android:</strong> use the <strong>SMS Retriever API</strong> (the backend appends the app's hash to the message; no\nSMS permission) or the <strong>SMS User Consent API</strong> (one-tap consent, no hash). Both are <code>androidMain</code>\ncode behind an interface the shared ViewModel calls — see <strong>kmp-expect-actual</strong>. The shared\nsend/verify endpoints do not change, except that SMS Retriever needs the backend to format the\nmessage with the hash.</li>\n<li><strong>iOS:</strong> a native text field with <code>textContentType = .oneTimeCode</code> gets the system's AutoFill\nsuggestion; check that your Compose Multiplatform text field exposes it before relying on it.</li>\n<li><strong>SMS-less verification on Android:</strong> Google's\n<a href=\"https://github.com/android/skills/tree/main/identity/digital-credentials/phone-number-verification\">phone-number-verification</a>\nskill (Credential Manager with carrier TS.43 tokens) covers the client and the backend exchange.</li>\n<li>Never send the OTP or phone number to logs; the verify request and response stay out of <code>BODY</code>\nlogging in every build.</li>\n</ul>\n<h2>Version notes</h2>\n<p>Fixes that change what an endpoint needs (Ktor and kotlinx.serialization changelogs, December 2026).\nOn an older version, apply the workaround; upgrade only when asked.</p>\n<table>\n<thead>\n<tr>\n<th>Library and issue</th>\n<th>Fixed in</th>\n<th>Symptom on older versions</th>\n<th>If you stay on it</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Ktor <a href=\"https://youtrack.jetbrains.com/issue/KTOR-9827\">KTOR-9827</a></td>\n<td>3.6.0</td>\n<td>An <code>Authorization</code> header you set on a request marked <code>markAsRefreshTokenRequest()</code> is removed, so a token endpoint that requires it rejects the call</td>\n<td>Call the token endpoint through the plain client, or make <code>sendWithoutRequest</code> return <code>false</code> for that path</td>\n</tr>\n<tr>\n<td>Ktor <a href=\"https://youtrack.jetbrains.com/issue/KTOR-9834\">KTOR-9834</a></td>\n<td>3.6.0</td>\n<td>Creating an <code>HttpClient</code> on Android eagerly initialises SLF4J; a start-up ANR was reported</td>\n<td>Do not build the client on the main thread during app start</td>\n</tr>\n<tr>\n<td>Ktor <a href=\"https://youtrack.jetbrains.com/issue/KTOR-9891\">KTOR-9891</a></td>\n<td>3.6.0</td>\n<td>CIO on Kotlin/Native collapses above about 50 concurrent connections (reported on the CIO server)</td>\n<td>Use the Darwin engine on iOS</td>\n</tr>\n<tr>\n<td>Ktor KTOR-9905</td>\n<td>3.6.2</td>\n<td>Following a redirect can carry <code>Cookie</code> and other sensitive headers to another host</td>\n<td>Disable redirects on credentialed clients if the API never redirects across hosts</td>\n</tr>\n<tr>\n<td>kotlinx.serialization 1.12.0 → 1.13.0</td>\n<td>1.13.0 reverts</td>\n<td>1.12.x wraps non-serialization exceptions thrown while decoding (e.g. <code>IllegalArgumentException</code> from an <code>init</code> block) in <code>JsonDecodingException</code>, a <code>kotlinx.serialization.json.JsonException</code>; 1.13.0 and ≤1.11 let them through unwrapped. <code>MissingFieldException</code> is never wrapped (1.12 adds the JSON path to its message)</td>\n<td>Name the version when triaging; catch <code>SerializationException</code> and Ktor's <code>ContentConvertException</code>, not a subclass</td>\n</tr>\n</tbody>\n</table>\n<h2>Quick reference — files for `GET orders/</h2>\n<table>\n<thead>\n<tr>\n<th>Layer</th>\n<th>File (commonMain)</th>\n<th>Contains</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>DTO</td>\n<td><code>orders/data/remote/dto/OrderDto.kt</code></td>\n<td><code>OrderDto</code>, <code>OrderItemDto</code></td>\n</tr>\n<tr>\n<td>Domain</td>\n<td><code>orders/domain/Order.kt</code></td>\n<td><code>Order</code>, <code>Money</code>, <code>OrderItem</code>, <code>OrderStatus</code></td>\n</tr>\n<tr>\n<td>Mapper</td>\n<td><code>orders/data/OrderMappers.kt</code></td>\n<td><code>toDomainOrNull()</code></td>\n</tr>\n<tr>\n<td>API</td>\n<td><code>orders/data/remote/OrdersApi.kt</code></td>\n<td>interface + <code>KtorOrdersApi</code></td>\n</tr>\n<tr>\n<td>Repository</td>\n<td><code>orders/domain/OrdersRepository.kt</code>, <code>orders/data/OrdersRepositoryImpl.kt</code></td>\n<td><code>ApiResult&lt;Order&gt;</code></td>\n</tr>\n<tr>\n<td>Use case</td>\n<td><code>orders/domain/GetOrderUseCase.kt</code></td>\n<td>only if the project uses them</td>\n</tr>\n<tr>\n<td>DI</td>\n<td><code>orders/di/OrdersModule.kt</code></td>\n<td>bindings, added to the app module list</td>\n</tr>\n<tr>\n<td>Tests</td>\n<td><code>commonTest/.../orders/*Test.kt</code></td>\n<td>mapper, API, repository, fake repository</td>\n</tr>\n</tbody>\n</table>\n<h2>Verify</h2>\n<p>Report each check as <code>PASS</code>, <code>FAIL</code> or <code>NOT RUN</code> (with the reason). Do not report a check you did\nnot run. Read <code>settings.gradle.kts</code> for the real module name; the Android host-test task is\n<code>testDebugUnitTest</code> with <code>com.android.library</code> and <code>testAndroidHostTest</code> with\n<code>com.android.kotlin.multiplatform.library</code>.</p>\n<pre><code>./gradlew :shared:testDebugUnitTest --tests \"com.example.app.orders.*\"     # fast JVM loop\n./gradlew :shared:iosSimulatorArm64Test --tests \"com.example.app.orders.*\" # Kotlin/Native\n./gradlew :shared:allTests                                                 # everything before you finish\n./gradlew :composeApp:assembleDebug                                        # app still builds\n</code></pre>\n<p>Static checks (adjust <code>shared/src/commonMain</code> to the module you changed; review every hit):</p>\n<pre><code>grep -rnE \"val [A-Za-z0-9_]+: [^?=]+(,|$)\" --include=*Dto.kt shared/src/commonMain           # non-null DTO fields\ngrep -rnE 'client\\.(get|post|put|patch|delete)\\(\"[^\"]*\\$' --include=*.kt shared/src/commonMain | grep -v encodeURLPathPart   # unencoded path params\ngrep -rn \"HttpClient(\" --include=*.kt shared/src/commonMain                                   # clients outside the network module\n</code></pre>\n<h2>Common mistakes</h2>\n<table>\n<thead>\n<tr>\n<th>Mistake</th>\n<th>Why it bites</th>\n<th>Fix</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>DTO fields copied as non-null from the sample</td>\n<td>The sample had every field; production data does not</td>\n<td>Nullable, <code>= null</code>, decide in the mapper</td>\n</tr>\n<tr>\n<td>Money or quantity defaulted to <code>0</code></td>\n<td>A missing total renders as \"free\" and may be acted on</td>\n<td>Treat as required: drop or fail</td>\n</tr>\n<tr>\n<td><code>\"orders/$id\"</code></td>\n<td>Ids containing <code>/</code>, <code>?</code> or <code>#</code> rewrite the request</td>\n<td><code>\"orders/${id.encodeURLPathPart()}\"</code></td>\n</tr>\n<tr>\n<td>Path starts with <code>/</code></td>\n<td>Drops the base path (<code>/v1/</code>), request hits the wrong URL, 404</td>\n<td>Relative path</td>\n</tr>\n<tr>\n<td>New <code>HttpClient</code> or <code>install(...)</code> in the feature</td>\n<td>No auth, no timeouts, no log redaction</td>\n<td>Inject the shared client by qualifier</td>\n</tr>\n<tr>\n<td><code>try</code>/<code>catch</code> in the API class</td>\n<td>Errors mapped in two places, differently</td>\n<td>Only the repository's error boundary maps</td>\n</tr>\n<tr>\n<td>Catching <code>Exception</code> without rethrowing <code>CancellationException</code></td>\n<td>Cancelled screens keep running and report fake failures</td>\n<td>Use the project's error boundary helper</td>\n</tr>\n<tr>\n<td>Pass-through use case in a project without use cases</td>\n<td>Extra layer, extra DI, no behaviour</td>\n<td>Follow the project's layering</td>\n</tr>\n<tr>\n<td>Tests with their own <code>Json { }</code> or a hand-built client</td>\n<td>Pass while production parsing fails</td>\n<td>Build the test client with the production factory and <code>MockEngine</code></td>\n</tr>\n<tr>\n<td>Only the happy path tested</td>\n<td>404, 401 and malformed bodies ship untested</td>\n<td>The four repository error tests are mandatory</td>\n</tr>\n<tr>\n<td>Triaging a parse failure without the kotlinx.serialization version</td>\n<td>1.12.x and 1.13.0 surface different exception classes for the same bad payload</td>\n<td>Read the catalog version first (<strong>Version notes</strong>)</td>\n</tr>\n<tr>\n<td>OTP auto-fill by reading the SMS inbox</td>\n<td>Android 17 delays the message three hours; the user waits or gives up</td>\n<td>SMS Retriever or SMS User Consent in <code>androidMain</code></td>\n</tr>\n<tr>\n<td>Endpoint added but module not registered</td>\n<td><code>NoDefinitionFoundException</code> at runtime, only on the screen that needs it</td>\n<td>Add the module to the app's list; run the DI verification test</td>\n</tr>\n</tbody>\n</table>\n<h2>Related skills</h2>\n<ul>\n<li><strong>kmp-data-layer</strong> — the architecture these steps implement: client, DTO rules, <code>ApiResult</code>, offline-first.</li>\n<li><strong>kmp-koin-di</strong> — module registration and the DI verification test.</li>\n<li><strong>kmp-room-database</strong> — caching the response locally.</li>\n<li><strong>kmp-expect-actual</strong> — the Android SMS Retriever / User Consent behind a shared interface.</li>\n<li>Android 17 SMS OTP changes: <a href=\"https://developer.android.com/about/versions/17/behavior-changes-17\">https://developer.android.com/about/versions/17/behavior-changes-17</a>\nand <a href=\"https://developer.android.com/about/versions/17/behavior-changes-all\">https://developer.android.com/about/versions/17/behavior-changes-all</a></li>\n<li>Ktor changelog: <a href=\"https://github.com/ktorio/ktor/blob/main/CHANGELOG.md\">https://github.com/ktorio/ktor/blob/main/CHANGELOG.md</a>; kotlinx.serialization\nchangelog: <a href=\"https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md\">https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md</a></li>\n<li>Ktor client testing: <a href=\"https://ktor.io/docs/client-testing.html\">https://ktor.io/docs/client-testing.html</a></li>\n<li>Ktor requests (parameters, bodies, forms): <a href=\"https://ktor.io/docs/client-requests.html\">https://ktor.io/docs/client-requests.html</a></li>\n</ul>\n","files":[{"path":"references/test-templates.md","sizeBytes":7109,"isText":true},{"path":"SKILL.md","sizeBytes":20634,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-12-03T17:29:58.139479Z","sha256":"C5A785EF81DD2301BB27CFE437B765F9C237E411F70C7408DEE134A20575A390","sizeBytes":10943},"review":null,"source":{"repositoryUrl":"https://github.com/Kushpawan/kmp-mobile-skills","path":"skills/kmp-api-endpoint","license":"Apache-2.0","commit":"c04c11f696aa7a0f3c67761e5e48a7fd8201efa9","subtreeSha":"54763CBEEBB82E0A2B349118AF7E9B12A019FF51793BB3BAF06EF34BD488154D","lastSyncedAt":"2026-12-03T17:29:47.313948Z"},"reviewedAt":"2026-12-03T17:30:35.21369Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/Kushpawan/kmp-mobile-skills/tree/main/skills/kmp-api-endpoint"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install kushpawan-kmp-mobile-skills@llmmart"},{"target":"git","command":"git clone https://github.com/Kushpawan/kmp-mobile-skills.git"}]}