add-api-service
Add a Ktor-backed network request end-to-end — request/response DTOs, an API service, a repository, and a ViewModel call.
Skill by KotlinFoundation
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/kotlinfoundation-add-api-service
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend, devops, data
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 26, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/add-api-service
What's inside
- Skill name
add-api-service- Description
- Add a Ktor-backed network request end-to-end — request/response DTOs, an API service, a repository, and a ViewModel call. Use when the user wants to fetch or post data over HTTP, call any REST/third-party API, or extend an AI provider call (OpenAI/Replicate route through AiTransport — this skill explains how). To deploy the Cloud Functions AI proxy itself, use integrate-web-proxy instead.
- License
- MIT
- Instructions
- 92 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# Add an API service (network request)
Generic Ktor call to **any** URL — this is not tied to the project's own backend. Follow the layering:
DTOs → API service → repository (`Result` wrapping) → ViewModel.
Paths below are under `shared/src/commonMain/kotlin/com/kotlinfoundation/koko/`.
> **AI services are special.** The OpenAI/Replicate services route through `AiTransport` (proxy vs direct
> mode) rather than calling the client directly. In **proxy** mode the response is the
> `{statusCode, errorMessage, data}` envelope (`AiApiBaseResponse<T>`); in **direct** mode the provider
> returns its **raw body at the top level** and `AiTransport` re-wraps it into the same envelope — so the
> DTOs (`T`) stay identical. If you add a new AI provider, mirror this: pass your `directUrl` + auth
> headers + key-readiness to `AiTransport.execute`. Non-AI services just use the Ktor client directly, as
> below.
## 1. DTOs — `data/source/remote/request/` and `data/source/remote/response/`
`*Request` / `*Response` suffixes are required. All DTOs `@Serializable` + `@SerialName`. Response DTOs
carry an `asDomain()` mapper. **Return raw types, never `Result`** — repositories do the wrapping.
```kotlin
// response/GetJobsResponse.kt
@Serializable
data class GetJobsResponse(
@SerialName("jobs") val jobs: List<JobResponse>,
) {
fun asDomain(): List<Job> = jobs.map { it.asDomain() }
}
@Serializable
data class JobResponse(
@SerialName("id") val id: String,
@SerialName("title") val title: String,
) {
fun asDomain(): Job = Job(id = id, title = title)
}
```
## 2. API service — `data/source/remote/apiservices/`
Take the shared `HttpClient` (base URL + JSON + logging are already configured in
`data/source/remote/HttpClientFactory.kt`). Return raw DTOs; let exceptions propagate.
```kotlin
class JobApiService(private val httpClient: HttpClient) {
suspend fun getJobs(request: GetJobsRequest): GetJobsResponse =
httpClient.post("/jobs") { setBody(request) }.body()
}
```
Register in `root/Di.kt` `dataModule` alongside the existing `factoryOf(::ApiService)`:
```kotlin
factoryOf(::JobApiService)
```
## 3. Repository — `data/repository/`
Concrete class (no interface). Wrap in `Result` via `backgroundExecutor.execute { }` — it already
catches, logs, and returns `Result.failure`, so **no redundant try-catch**.
```kotlin
class JobRepository(
private val jobApiService: JobApiService,
private val backgroundExecutor: BackgroundExecutor = BackgroundExecutor.IO,
) {
suspend fun getJobs(page: Int, limit: Int): Result<List<Job>> =
backgroundExecutor.execute {
val response = jobApiService.getJobs(GetJobsRequest(page, limit))
Result.success(response.asDomain())
}
}
```
Register in `dataModule`: `single { JobRepository(get()) }`.
## 4. Call from a ViewModel
Inject the repository, call the suspend function inside `viewModelScope`, fold the `Result` into UiState.
## Testing
Use Ktor `MockEngine` to stub responses/errors — never hit the real network in unit tests
(`shared/src/commonTest/`). See `AiGuidelines/tech/api_services.md`.
Validate with the `run-quality-gates` skill.
## Talking to Firebase?
If the endpoint is backed by Firestore — cloud sync, cross-device state, a server-authoritative balance
— start from `sync-data-firebase`, not here. No Firebase client SDK supports the `wasmJs` target, so the
approach has to be decided with the developer before any code is written. This skill still describes the
client layering once that decision is made.From KotlinFoundation/kmp-contest-starter-kit, MIT.
More from KotlinFoundation/kmp-contest-starter-kit
- 0.609score
add-permission
KotlinFoundation
Request a runtime permission (notifications, camera, gallery out of the box; location, microphone or any other after adding its Calf module) via the app-level…
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
configure-environment
KotlinFoundation
Reference catalog (a lookup, not a setup action) of every environment configuration value — local.properties API keys, the gradle.properties subscription…
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
capture-app-screens
KotlinFoundation
Render the app's own screens to plain PNGs at storefront pixel sizes (1284×2778 etc.) from @Preview @StoreScreenshot composables — the real UI and nothing…
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
publish-release
KotlinFoundation
Build the signed release artifacts and ship them — Android AAB to a Play track and iOS archive to TestFlight/App Store, via Fastlane lanes or the tag-driven…
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
refactor-package
KotlinFoundation
Rename the app's package / applicationId / iOS bundle ID and display name across the whole project.
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
run-quality-gates
KotlinFoundation
Run the same lint, test, screenshot, and build checks as CI.
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
getting-started
KotlinFoundation
Phase-1 blueprint for the KMP starter kit — get the app running locally on your own device, rebrand it, and build your MVP features from the PRD (all…
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
setup-analytics
KotlinFoundation
Enable Firebase Analytics, Crashlytics, and Remote Config feature flags in the KMP app — log events, add a flag, toggle it at runtime via Remote Config, and…
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
setup-appstore-connect
KotlinFoundation
Manually create and configure the app in App Store Connect — bundle id, version, categories, age rating, privacy, review info, and localized metadata.
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
setup-subscriptions
KotlinFoundation
Wire up in-app subscriptions in KMPStarterKit — pick the provider (Adapty default or RevenueCat) via one gradle property, add the two SDK keys, create store…
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
sync-data-firebase
KotlinFoundation
Sync app data to Firebase — Firestore documents, cross-device sync, server-authoritative state (credit balances, settings, user profiles, saved items).
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
koko-mobileapp-getting-started
KotlinFoundation
Phase 1 developer journey guide for the MobileApp directory.
SkillBFreshness: B★ 28Claude Code +9
Signals
- Stars
- 28
- Forks
- 13
- Open issues
- 1
- Last commit (this folder)
- Aug 10, 2026 (2 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from KotlinFoundation
- 0.609score
capture-app-screens
KotlinFoundation
Render the app's own screens to plain PNGs at storefront pixel sizes (1284×2778 etc.) from @Preview @StoreScreenshot composables — the real UI and nothing…
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
configure-environment
KotlinFoundation
Reference catalog (a lookup, not a setup action) of every environment configuration value — local.properties API keys, the gradle.properties subscription…
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
getting-started
KotlinFoundation
Phase-1 blueprint for the KMP starter kit — get the app running locally on your own device, rebrand it, and build your MVP features from the PRD (all…
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
publish-release
KotlinFoundation
Build the signed release artifacts and ship them — Android AAB to a Play track and iOS archive to TestFlight/App Store, via Fastlane lanes or the tag-driven…
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
refactor-package
KotlinFoundation
Rename the app's package / applicationId / iOS bundle ID and display name across the whole project.
SkillBFreshness: B★ 28Claude Code +9 - 0.609score
add-permission
KotlinFoundation
Request a runtime permission (notifications, camera, gallery out of the box; location, microphone or any other after adding its Calf module) via the app-level…
SkillBFreshness: B★ 28Claude Code +9
Cite this page
add-api-service skill. Agent Mart. https://agentmart.dev/skills/kotlinfoundation-add-api-service (last updated 2026-10-24)