# Scalable API Response Handling Across Multi-Layered Architectures with Sandwich

DevFeed: [Scalable API Response Handling Across Multi-Layered Architectures with Sandwich](<https://devfeed.tech/articles/scalable-api-response-handling-across-multi-layered-architectures-with-sandwich-25924.md>)

Original publisher: [Read original article](<https://proandroiddev.com/scalable-api-response-handling-across-multi-layered-architectures-with-sandwich-39ab02ae8c90?source=rss-9bb203a4ab2e------2>)

Author: Jaewoong Eum

Published: 2026-02-08T06:25:14Z

Content type: tutorial

Language: en

Sources: [Stories by Jaewoong Eum on Medium](<https://devfeed.tech/sources/stories-by-jaewoong-eum-on-medium.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [API](<https://devfeed.tech/topics/api.md>), [kotlin-coroutines](<https://devfeed.tech/topics/kotlin-coroutines.md>), [Error Handling](<https://devfeed.tech/topics/error-handling.md>), [Network](<https://devfeed.tech/topics/network.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [api](<https://devfeed.tech/tags/api.md>), [code](<https://devfeed.tech/tags/code.md>), [communication](<https://devfeed.tech/tags/communication.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [exceptions](<https://devfeed.tech/tags/exceptions.md>), [flow](<https://devfeed.tech/tags/flow.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-multiplatform](<https://devfeed.tech/tags/kotlin-multiplatform.md>), [mvi](<https://devfeed.tech/tags/mvi.md>), [mvvm](<https://devfeed.tech/tags/mvvm.md>), [network](<https://devfeed.tech/tags/network.md>), [networking](<https://devfeed.tech/tags/networking.md>), [presentation](<https://devfeed.tech/tags/presentation.md>), [responses](<https://devfeed.tech/tags/responses.md>), [retrofit](<https://devfeed.tech/tags/retrofit.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

## AI overview

This tutorial explains how to handle Retrofit API responses, errors, and exceptions across multi-layered Android architectures such as MVVM and MVI. It presents Sandwich as a type-safe, composable approach and covers response handling, composition, merging, global error mapping, and Flow integration.

## Source excerpt

Unsplash@picoftasty Modern Android applications commonly adopt multi-layered architectures such as MVVM or MVI, where data flows through distinct layers: a data source, a repository, and a ViewModel (or presentation layer). Each layer has a specific responsibility, and network responses must propagate through all of them before reaching the UI. While this separation produces clean, testable code, it introduces a real challenge: how do you handle API responses, including errors and exceptions, as they cross each layer boundary? Most developers solve this by wrapping API calls in try-catch blocks and returning fallback values. This works for small projects, but as the number of API calls grows, the approach creates ambiguous results, scattered boilerplate, and lost context that downstream layers need. You end up with ViewModels that cannot tell whether an empty list means "no data" or "network failure," repositories that swallow important error details, and data sources that repeat the same error handling pattern dozens of times. In this article, you'll explore the problems that emerge when handling Retrofit API calls across layered architectures, why conventional approaches break down at scale, and how Sandwich provides a type safe, composable solution that simplifies response handling from the network layer all the way to the UI. You'll also walk through the full set of Sandwich APIs, from basic response handling to advanced patterns like sequential composition, response merging, global error mapping, and Flow integration, each with real world use cases that show when and why you would reach for them. Retrofit API calls with coroutines Most Android projects use Retrofit with Kotlin coroutines for network communication. A typical service interface looks like this: https://medium.com/media/ebcba33386d664d1cf69a89234d2e22a/href The service returns a List<Poster> directly. Retrofit deserializes the JSON response body and gives you the data. This works perfectly when the