Build a small client
Fetch JSON, model it with data classes and render it with states.
What you will be able to do
- Use a data class for the response.
- Keep the API client separate.
- Model loading, error and content.
- Test the parser and the view model.
In plain English
The capstone fetches a list of lessons, parses it into data classes and renders loading, error and content states. Keep the network layer separate from the UI so both are testable.
data class Lesson(val title: String, val minutes: Int)
sealed interface UiState {
data object Loading : UiState
data class Content(val lessons: List<Lesson>) : UiState
data class Error(val message: String) : UiState
}Your turn
EasyAdd a loading state
Add a Loading object to the UiState interface.
KOTLIN · starter
sealed interface UiState {Check your understanding before moving on.
Knowledge checkQuestion 1
Why model UI state as a sealed interface?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.