Mock your APIs without any code change with Charles Proxy

Prateek Srivastava
Mocklets
Published in
3 min readJan 21, 2020
Using Charles Proxy with Mocklets

If you have ever developed any front-end application whether web or mobile, its very likely you must have heard about Charles Proxy. But for those who haven’t, Charles is, as described on its site:

Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information).

Now, in the last article, we learned about how Mocklets can be used to speed up the development process. But speed only doesn’t always suffice the needs of a better development process. We need a quality product too. This is where Mocklets comes to rescue, again.

Quality assurance is a critical part of application development. Mocklets empowers the quality testing by allowing testing of edges cases and inducing production environment which actual servers cannot reproduce reliably. But since quality testing will be taking place on your release candidate build, it is very late to keep making changes in your code to point API requests to Mocklets.

So how do we point some of our API requests to Mocklets, while keep pointing to actual server APIs, without making any code changes.

Proxying to Mocklets with Charles

Before moving on to this section, we need to setup Charles Proxy to intercept the API calls made from your app. There is a nice article here, about setting up Charles Proxy.
If you already know how to setup Charles, you are good to proceed.

Now that Charles Proxy is setup, it will start showing all the calls being made from our application.

Let’s take an example where our application is making a GET request to http://dummy.restapiexample.com/api/v1/employees which responds with the list of employees.

Response from server API

Now, let’s try to forward requests made to above API to Mocklets. For that we first need to create a mock API on Mocklets.

Now, we will map our API request, going to our server, to be forwarded to Mocklets API. (Right click on the specific request > Select “Map Remote”)

Once you see Edit Mapping dialog, provide the details required to forward the request and press OK.

And, that’s all, you are all done. From now onwards, all the requests you make to the specified API, those will be forwarded to Mocklets API and you will receive a mock response.

Response from Mocklets API

Isn’t it super easy!!!

Using Mocklets with Charles Proxy, gives you flexibility to send some requests to Mocklets, while keep pointing to actual server for rest, that too without making any changes in application code. This ability make Mocklets indispensable to application development process.

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!!!

--

--