Mock API for Android developers

Karishma Agrawal
3 min readJun 24, 2021

--

Photo by Yancy Min on Unsplash

Sometimes when we have to work on a feature that requires backend and frontend support. And there are diff teams who work on the front and backend. You are from the front-end team, you can’t wait for the backend team to complete their API because of the deadline. In that case, we work with a dummy API, which contains the same JSON structure. It can be done in multiple ways, The best way to go ahead is to mock your API.

There are multiple ways to mock API, we are gonna discuss a few which we personally use at HealthifyMe.

Mockable.io

Mockable has a simple UI to use.

You will see two options here, REST and SOAP. Select Rest Mock and you will see a window like below.

Mockable.io

The path is the base URL which you can use in your app to get API response, then from verb select API type its get API, post API, put API, etc. Then choose content-type, and in the response body, you can add JSON that you want to receive in your application.

Let’s take a sample JSON and create a mockable API.

In path, I am adding location. Now click on save. Once you clicked on save you will see a popup saying mock is stopped. Go to the main window Domain demo…

Click on stopped to start the API. Once it started working open the API description and copy the URL and run it in the browser to check if it’s working or not.

https://demo1732035.mockable.io/location

Now use this base URL in your project to get data.

Pass your mockable API URL in this method.

Now create retrofit get call using location as endpoint.

Postman

Using postman to create a mock server is 3 step process.

Step 1: Click on new and Select mock server

Step 2: Define method type and response body

Step 3: Define mock server name

It’s done, in my case the base url is https://73d458fc-e495-4034-943b-807c83004b46.mock.pstmn.io . You can test your application using it.

One biggest advantage of using Postman is you can change the response dynamically and it’ll start reflecting immediately to the same endpoint, which is not the case for the previous option.

Hope this will help you in your next development.

If you have any feedback please write me back at karishma.agr1996@gmail.com.Your claps are really appreciated to help others find this article 😃 .

--

--

Karishma Agrawal

Android Developer @Eventbrite | Wanted to be a writer so I write code now | Reader