android-retrofit

Configures Retrofit networking in Android with coroutines, OkHttp, Hilt, and repository error handling.

1|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/chmonya-inc/dnd-manager --skill android-retrofit-chmonya-inc
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: android-retrofit
Source: https://github.com/chmonya-inc/dnd-manager/tree/main/.agents/skills/android-retrofit
Command: npx skills add https://github.com/chmonya-inc/dnd-manager --skill android-retrofit-chmonya-inc

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up type-safe HTTP networking in Android involves many decisions — service interface design, OkHttp configuration, dependency injection, and error handling — and getting any of them wrong leads to leaked exceptions, duplicated auth logic, and ViewModels coupled to network internals. ## Core Features & Use Cases - Service Interface Patterns: Declare suspend endpoints with @GET/@POST, path and query parameters, request bodies, multipart uploads, and headers, with guidance on when to use Response<T> versus direct return types. - Hilt & OkHttp Setup: Provides a complete Hilt module wiring kotlinx.serialization, a debug-gated logging interceptor, timeouts, and Retrofit service providers. - Repository Error Handling: Maps HttpException and IOException to a unified sealed DataError hierarchy so ViewModels never depend on Retrofit types. - Use Case: When adding a new REST API to an Android app, use this Skill to scaffold the service interface, auth interceptor, Hilt module, and repository with correct RIGHT vs WRONG patterns from the start. ## Quick Start Set up a Retrofit service interface with Hilt and repository-level error handling for my Android app's user profile API.

Frequently Asked Questions about android-retrofit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up Retrofit with coroutines in Android?▼

Declare all service interface methods as suspend functions and return the body type directly for simple cases. Retrofit natively supports coroutines, throwing HttpException on non-2xx responses, which you catch in the repository layer.

When should I use Response<T> vs direct return type in Retrofit?▼

Use Response<T> only when you need status codes, headers, or error body content such as validation messages. For standard success cases, return the body type directly — it is non-null and Retrofit throws HttpException automatically on errors.

How do I add an auth token to every Retrofit request?▼

Use an OkHttp Interceptor that reads the token from a TokenProvider and adds the Authorization header to every request. This avoids repeating @Header parameters on each endpoint, which is error-prone and easy to forget.

Should ViewModels catch HttpException directly?▼

No. The repository should catch HttpException and IOException and map them to domain error types like a sealed DataError class. This keeps ViewModels independent of the networking implementation, so swapping Retrofit for Ktor requires no UI changes.

How do I configure Retrofit with Hilt and kotlinx.serialization?▼

Create a Hilt module providing a configured Json instance, an OkHttpClient with debug-gated logging and timeouts, and a Retrofit instance using json.asConverterFactory. Then provide each service interface via retrofit.create().