Here I want to talk about mock responses for your Retrofit.

Sometimes we should continue mobile development even backend not ready. We can be never blocked on it if will use mock responses. Sure we need specify JSON response before starting. But we need only JSON format of the backend response to start.

Let’s see.

First we need create implementation of Interceptor and this class will contains all logic for server responses.

Feel free parse requests and create your own if/else cases

Here is sample

The key method is public Response intercept(Chain chain). You can play inside this method and prepare responses for your client side.

I’ve created sample login form with mock server requests

OkHttp log


Download it from github

Feel free download source code of the sample application from my github

Nice codding


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.