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? If not then here is a great article regarding that. This error is because of that.

Mockable.io:

Mockable has also a simple UI to use. You can create a custom path for your API, Verb, Headers, Response status, content type, content-encoding, response body and response delay.

Mockable.io

Wow!! So many customizations. But it comes at a price(literally). If you use the free version, then the mock server lasts for 24 hours (if you use a guest account) or 3 months of inactivity(if you create an account). If you go for the premium version, then you’ll get some nice features.

For most of us, it’s more than enough. But if you want little more than that, then this is the best option available out there.

Postman:

Postman is a collaboration platform for API development. It also provides a nifty feature to create a mock server that we can use for our purpose. Creating a “Mock Server” is a 3 step process. Let’s see:

Click on “New” and select “Mock Server”.

step 1

2. Define your desired request path, response code, and request body.

3. Name your mock server and click on next. To make your mock server private you need Postman API key.

step 3

Voila. Now your mock server is ready. Note down the base URL of your mock server. In my case, it is https://d4db74b8-e026-4ee9-aceb-3ac9c296fbb2.mock.pstmn.io. Now use this mock server URL to test your app.

Advantage:

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 two options.

You can visit this link for further guidance. https://youtu.be/fgtDZPOPzLU