Unblock your app development with Mocklets

Prateek Srivastava
Mocklets
Published in
5 min readOct 17, 2019

I couldn’t get the work done, the server API was down again.

I’m blocked as the back-end APIs that are required for the feature, I am working on ,are not done yet.

I wasn’t able to get much work done. The VPN was down, so I couldn’t connect to the API.

We do hear statements like these at our workplace, more often than not. We work in a environment where multiple inter-dependent teams work on same feature/product at the same time. This puts front-end teams (mobile/web) in a situation where they have to start working on a feature well before the back-end is even ready, which results in multiple code iterations to integrate the back-end changes later in development cycle and increase in development time.

You might say that it’s really not a problem, as the cross-platform teams can agree upon the JSON response so no one is blocked by anyone. And then front-end guys can just hard-code that response in their application and start working. But is it really a feasible solution?

The problem with this approach is that, it is very difficult to determine a complete and perfect JSON response even before starting to work on the feature. So any changes in decided response will result in reoccurring changes in front-end code, again adding up development time.

The other and better way is use mock APIs which will simulate the actual APIs. One of the tools that lets you create and share mock APIs with any code changes is Mocklets. As Mocklets APIs can be shared, so all the teams can use or modify the APIs as per their use.

Why use Mocklets to mock APIs?

  1. Gives you a heads up: Mocklets allows you to begin development without waiting for the back-end team to build the services you need. And if you haven’t decided how to design your web services, mocking allows you to rapidly prototype different potential response shapes to see how they work with your app.
  2. No code dependency: Mocklets don’t require any code changes to be made on front-end systems, and behaves exactly like actual servers. This gives you the flexibility of using the same response across different platform(mobile or web).
  3. Share among teams: Mocklets collection can be shared among teams, which allows better collaboration between teams to manage the mock APIs till the actual server isn’t ready.
  4. Simulate errors: With Mocklets, you can assign multiple responses to your API pointing to different HTTP status codes, which helps testing your application against various network errors.
  5. Test edge cases: Mocklets offers features like delayed responses and randomised responses. These help simulate edge cases to test your applications which will be very difficult to reproduce in actual production environment.

Creating a mock response in Mocklets

Well, now we arrive to the main part of the article, creating your first mock API. You can create mock APIs either by manually adding mock APIs from the dashboard or through importing Open API Specifications.

Create new mock API

Let’s walk through the steps of creating your first mock API manually.
Firstly, set a label, URL endpoint and HTTP method for your mock API. This concludes the request part of your API.

Now, its time to set the response for your API. Set appropriate HTTP status, headers(Content-Type, Content-Encoding), Response Delay(optional) and a Response Body. You can choose a data type for response body from Content-Type select.

You are all set, now click on Create Api button and your API is ready to be used.

Upload Open API Specification

Open API Specification is the most widely used description language for REST APIs. Mocklets supports the automatic generation of mock APIs from imported Open API Specifications. You just have to upload your specs on Mocklets dashboard.

Go to the Collection page and click the Open API Spec button. Then paste your YAML definition into the text editor, pick your duplicate policy and hit Upload Specification. For more information how to use Open API Specifications, please refer our documentation page.

Mocklets API Dashboard

Once the API is created, you can make modifications to it. Some of the features that our mock APIs offer is listed below.

You can now add additional responses to your mock API, and set any one of those as active to use that specific response.

Also, you can set Randomised Responses, which will set the API to return random responses on each API request.

Using mock API

Additional Features

  1. Use as Proxy: When working with an existing APIs, it can be useful to pass some requests through to it for testing, while serving mock responses for others. You can use Mocklets dashboard to enable Proxy feature for any mock API on the go.
  2. Integration with external tools: Mocklets allows you to import/export your mock API to external tools like JSON Editor Online, providing a lot of flexibility when it comes to editing your response body.
  3. View request logs: Mocklets stores all the API requests and response for a limited duration, which enables you to go back and investigate any bug with specific response.

Creating a mock API for your application helps you to develop your applications/features, independently of your back-end server. And Mocklets can be a very useful tool in achieving this. It can be helpful not only during development cycle, but also during testing phase by simulating edge case scenarios.

Try out Mocklets, and if you need more information about how to use this tools, visit their documentation page.

Stay tuned for next article

Mocklets also supports file hosting, which can be used to share your assets as well as use them in your mock APIs. Stay tuned for the next article where I will discuss more about their file hosting feature.

Happy coding!!!

--

--