An easy way to mock an API response using Retrofit, OkHttp, and Interceptor

Wahib Ul Haq
4 min readMar 22, 2019

Many times, Android developers need to start implementing features even when the backend is not ready yet. An easier way is to ask the backend developer to create the API service and just send fake content for the sake of it. The underlying notion is that we are not backend developers and it is not our responsibility to provide the endpoint.

Do you even Agile, Bro? What about User Stories and Acceptance Criteria?

I know what you are thinking and you are not wrong. But here’s the thing: Many times there are situations when it is not possible to go by the book. For example, it can happen that cross-platform teams start working together. The best you can do is to come together with backend developer and agree on the JSON response so no one is blocked by anyone.

Ok, this is sorted out but how Android developers can test their feature implementation against backend response without API being live?

There are a couple of options:

--

--

Wahib Ul Haq

Senior Program Manager at Diconium • Dev Advocate • Talks about Tech, DevRel, Soft skills, Careerintech & Partnerships • Co-Organizer @DevRelMunich