Photo by Simon Ray on Unsplash

Just Fake It: Mock API 101 for Android Developers

Abhilash Das
Geek Culture

--

Mocks come into play in different stages of the app development lifecycle. Let’s assume you have a separate team of front end and back end developer. When you start working on the app, if the API is not ready, then you are stuck in the middle of nowhere.

The best way to go ahead with development is to mock your API. Build your app from the expected response and when your backend API is ready, just replace it with the actual base URL. In addition to that, you can test all the backend scenarios without bothering your backend team.

There are various ways to mock an API. We are gonna discuss some of the options I personally use.

Mocky.io:

Mocky is a free service and you can mock your HTTP responses to test your REST API. You can set Status code, content-type, body and Custom headers in Advanced Mode. It’s easy to use and doesn't require any brainstorming.

mocky.io

There is one shortcoming though. It will break in Android pie devices and higher. It’ll throw java.net.UnknownServiceException. (and javax.net.ssl.SSLHandshakeException even if you use https). Have you ever heard of ClearText the issue…

--

--