How to Inspect & Modify HTTP traffic from iOS Apps

Introduction

Modern app development has made it quintessential for frontend developers to be equipped with tools that help them develop, test and ship their apps quickly. One such powerful tool is Requestly. It is an open-source platform that allows developers to inspect and modify HTTP traffic from their iOS apps easily.

By utilising Requestly, you can significantly enhance your development workflow and save valuable time. So in this blog post, we’ll understand how we can use Requestly to inspect network traffic, simulate API failures and redirect API calls on iOS apps.

Setup

  • First, head over to Requestly and download and install the desktop app on your system.
  • Once installed, open the Requestly desktop app and click on Connect apps.
  • Choose the Mobile apps and browsers section.
  • Click on the iOS External Device option and click on Setup Instructions.
  • For the next steps, you should get a list of setup instructions that will tell you how to install a proxy on your iOS device to enable Requestly to intercept traffic from your iOS device.
  • Let’s follow these instructions to setup a proxy on our iPhone.

Install Proxy and Add Certificate on your iPhone

To enable Requestly to intercept and modify network traffic from your iOS apps, you need to install a proxy on your iPhone and add the associated certificate. Here’s how:

  1. Install a proxy app like Charles Proxy or mitmproxy on your iPhone from the App Store.
  2. Follow the instructions provided by the proxy app to configure it as a system proxy on your device.
  3. Download the Requestly certificate from the Requestly desktop app or website.
  4. Install the Requestly certificate on your iPhone by following the instructions provided by the proxy app.

Inspecting Traffic

Now that you have set up Requestly and installed the proxy on your iPhone, let’s explore how to inspect HTTP traffic from iOS apps:

  1. Launch the app you wish to inspect, for example, let’s consider an internationally popular app like Airbnb or Twitter.
  2. Open the proxy app on your iPhone and start capturing network traffic.
  3. Use the Airbnb or Twitter app as you normally would. The proxy app will intercept and display the network requests and responses made by the app.
  4. Analyze the network requests to gain insights into the app’s behavior. You can examine the request headers, URL parameters, response headers, and more.

Modifying API Responses

Requestly enables you to modify API responses on the fly, allowing you to simulate different scenarios or test your app’s behavior in specific conditions. Here’s how to modify an API response:

  1. In the proxy app, locate the network request for the API you wish to modify. For example, let’s consider the API request for creating a new tweet in Twitter.
  2. Right-click on the network request in the proxy app’s network table to reveal a context menu.
  3. From the context menu, select the option to modify the response. A text editor will open, allowing you to modify the response body, headers, or status code.
  4. Make the desired changes to the API response. For instance, you can tweak the response data, add custom headers, or even simulate error conditions.

Simulating API Failures

With Requestly, you can also simulate API failures by setting the HTTP status code to indicate an error. This helps you verify how your app handles unexpected responses. Follow these steps:

  1. Locate the network request for the API you want to make fail in the proxy app.
  2. Right-click on the network request and select the option to modify the response.
  3. Change the HTTP status code to a relevant error code like 500 (Internal Server Error).
  4. Save the modifications, and the API request will now appear to fail, allowing you to observe how your app handles such scenarios.

Redirecting API Calls

Another powerful feature of Requestly is the ability to redirect API calls to a local development server. This is particularly useful when you want to test against a specific environment. Here’s how to redirect an API call:

  1. Identify the network request you wish to redirect in the proxy app.
  2. Right-click on the network request and choose the option to modify the response.
  3. Change the request URL to the desired local development server URL.
  4. Save the modifications, and the API request will now be redirected to your local development server, enabling you to test against your local environment.

Conclusion

Requestly serves as an invaluable tool for frontend developers working on iOS apps, enabling them to inspect and modify HTTP traffic seamlessly. By utilizing Requestly, you can gain deeper insights into app behavior, simulate different scenarios, and test your app’s resilience to unexpected situations. With its user-friendly interface and powerful features, Requestly empowers developers to enhance their development workflow and deliver high-quality apps. So, why not give Requestly a try and experience the convenience and efficiency it brings to iOS app development!

Remember, by incorporating Requestly into your development toolkit, you’ll be well-equipped to tackle the challenges that arise during app development and ensure your apps are robust and reliable. Happy debugging!

This article was written by:

Sagar Soni

Sagar Soni

Sagar is the co-founder and CTO of Requestly. When he's not busy architecting the next big thing in software development, you'll likely find him behind the wheel, cruising the streets and enjoying the thrill of the drive. For Sagar, it's all about the code by day and the open road by night.

Share this article:

You may also like