Modifying API responses with Proxyman (Part I)
Tags: httpproxy, ios, android, sslproxying
Published: 2020-02-19 04:02:14

---
title: Modifying API responses with Proxyman (Part I)
published: true
description: 
tags: #httpproxy #iOS #Android #sslproxying 
---
All applications these days seems to communicate over the internet. Most of the time, developers might not need paying much attention to such low level but sometimes, the app doesn't behave as we expect so we might want to use a proxy server like Wireshark, Fiddler, Charles or [Proxyman](https://proxyman.io/) to view all HTTP and HTTPS traffic between the device and the internet. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/y5q26itneulm9y6ttjdw.jpg)

This blog post explores one of the most useful features of those debugging tools that used daily by both QAs and developers named **Map Local**. It is powerful in debugging mobile and web applications as it allows developers and testers to change the response of the request, per the configured mappings, so that the response is transparently served from the new location locally as if that was the original request. 

---
###Get Started
Normally, testers will need to go through complicated flows in the app in order to have the response properties updated accordingly. The Map Local tool comes in handy to help us to quickly modify the response and change the required parameter to what we need, so that we are able to test different use cases.

Before we enable this feature, we first need to [download and launch Proxyman](https://dev.to/meg_review/web-debugging-proxy-for-macos-8gi). Then use **Cmd + F** to search for a specific name and **Pin** feature to isolate our wanted URL for later modification.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/c9xdnc9vkb6fzufosvn2.png)

Now we could easily double click the URL to see the content of both Request and Response 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0b88drgfv8z6fsjotd43.png)

At this time, we can choose one among three ways to enable the Map Local tool
- Right click the URL --> select Tools --> Map Local 
 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fte7kwe41c404vsmhjhy.png)

- Click Menu bar --> select Tools --> Map Local 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2nmyqrvenpoygfcgl1gb.png) 

- Use hotkey Option + Cmd +L

###Modify the Response
As soon as the Map Local is enabled, a new window would pop-up to help us monitor upcoming API calls. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/g3q6yqr67piyz02bui2l.png)

Because I have right-clicked an URL to enable Map Local, we can see that Proxyman auto-saves the origin Response of that URL and allows me to open it with my preferred Editor for modification. Thus, we can easily change those parameters for different testing purpose

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/axqhjufkrdmf1gdbf50m.png)

###Create Matching Rules

The next step is to define rules for upcoming Requests. This way, if Proxyman detect any API calls that match our rule, it will replace the content of the Response with our modified one in the local directory. 

Although Proxyman has pre-filled domain, we can type in any other domain name for mapping. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/jv18865ku3pcftlpqa87.png)

**Tips:** Check/uncheck the box to allow Proxyman to catch its sub-domains. For example, `/v1/posts` with **checked-box** will map all sub-URLs such as `/v1/posts?days_ago=0`. Meanwhile, `/v1/posts` with **unchecked-box** will only map the exact name `/v1.posts`

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/c0uhvuoyel1agzaamhmr.png)

After we select the previously modified Response and hit **Done**, a new rule will be created. As a result, any API calls that satisfy the rule will have the Response served from the local file

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/l8e95mefvywphfuilkve.png)


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/gi1sg0875vcfijgxug3p.png)

**Note:** we are able to select a different content format for mapping, for example

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xq6yojva6yl2ytqhpmqd.png)

... and the content might appear as follow

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/aorq8qc2tld01nzuk2i2.png)

As it might be a system vulnerability so be sure with your intended format of Response when testing in .production environment 


###What's next?
Modifying responses is very useful when it comes to developing and testing mobile applications. Using the "Map Local" will allow developers or testers to simulate responses from each request then put on the 'hacker hat' and try to debug or break the app. 

In the next blog post, we will discover how to use Proxyman's Map Local tool for mapping a whole directories instead of mapping individual files. It is an easy and convenient way when you need to test complicated response content including css, swf or image. Stay tuned and see you in our next blog post!

---

Proxyman is a high-performance macOS app, which enables developers to view HTTP/HTTPS requests from apps and domains on iOS device, iOS Simulator and Android devices. Get it at https://proxyman.io