Map DTOs to Domain Models
Separate network shapes from your domain types.
Two Kinds of Models
Your app actually has two shapes of data: the raw DTO from the API and the clean domain model your code wants.
What a DTO Is
A DTO, or data transfer object, mirrors the JSON exactly, even when the field names are messy or awkward.
@Serializable
data class UserDto(val user_name: String, val avatar_url: String?)All lessons in this course
- Define a Repository Interface
- Wrap the API Behind the Repository
- Map DTOs to Domain Models
- Expose Results as Flow