In order to quickly ship an Android app that your users love, you need to make sure it’s tested thoroughly. Today there are a number of tools that you can use to expedite the process of testing, building and shipping your apps quickly. One such tool is Requestly. It’s an open-source platform and you can use it to inspect and modify traffic from your Android apps easily.
In this blog post, I’ll walk you through how you can use Requestly to inspect network traffic, simulate API failures and redirect API calls on Android apps.
Setup
- First, head over to Requestly and download and install their desktop app on your system.
- Once installed, open the Requestly desktop app and click on Connect apps
- Then, choose the Mobile apps and browsers section:
- Then, choose the Android External Device option and click on Setup Instructions
- You will get a list of setup instructions that will tell you how to install a proxy on your Android device to enable Requestly to intercept traffic from your Android device.
Install Proxy and Add Certificate on your Android Device
To enable Requestly to intercept and modify network traffic from your Android apps, you need to install a proxy on your device and add the associated certificate. Follow these steps:
- Install a proxy app like ProxyDroid or Packet Capture from the Google Play Store on your Android device.
- Configure the proxy app as a system proxy on your device according to the instructions provided by the app.
- Download the Requestly certificate from the Requestly desktop app or website.
- Install the Requestly certificate on your Android device by following the instructions provided by the proxy app.
Inspecting Traffic
Now that you have set up Requestly and installed the proxy on your Android device, let's explore how to inspect HTTP traffic from Android apps:
- Launch the app you wish to inspect, such as an international popular app like Amazon or Twitter.
- Open the proxy app on your Android device and start capturing network traffic.
- Use the app as you normally would. The proxy app will intercept and display the network requests and responses made by the app.
- Analyze the network requests to gain insights into the app's behaviour. You can examine request headers, URL parameters, response headers, and more.
Modifying API Responses
Requestly allows you to modify API responses on the fly, enabling you to simulate different scenarios and test your app's behavior. Here's how to modify an API response:
- In the proxy app on your Android device, locate the network request for the API you want to modify. For example, let's consider the API request for creating a new tweet in Twitter.
- Long-press on the network request in the proxy app's network table to reveal a context menu.
- 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.
- Make the desired changes to the API response. You can tweak the response data, add custom headers, or simulate error conditions.
Simulating API Failures
With Requestly, you can 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:
- Locate the network request for the API you want to make fail in the proxy app.
- Long-press on the network request and select the option to modify the response.
- Change the HTTP status code to a relevant error code, such as 500 (Internal Server Error).
- 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
Requestly also allows you to redirect API calls to a local development server, facilitating testing against a specific environment. Here's how to redirect an API call:
- Identify the network request you wish to redirect in the proxy app.
- Long-press on the network request and choose the option to modify the response.
- Change the request URL to the desired local development server URL.
- Save the modifications, and the API request will now be redirected to your local development server, enabling you to test against your local environment.
SSL-Pinning
It's important to note that the Requestly desktop app does not offer SSL pinning capabilities. If the app you're testing utilizes SSL pinning, Requestly may not be able to intercept and modify its traffic. In such cases, additional measures or alternative tools may be required for testing.
Conclusion
By incorporating Requestly into your Android app development toolkit, you can inspect and modify HTTP traffic with ease. Requestly enables you to gain valuable insights into app behavior, simulate various scenarios, and test your app's resilience to different network conditions. With its user-friendly interface and powerful features, Requestly helps you streamline your development workflow and deliver high-quality Android apps. So, give Requestly a try and experience the convenience and efficiency it brings to your Android app development process!
Remember, by leveraging Requestly, you'll be equipped with a powerful toolset to tackle the challenges of app development, ensuring your apps are robust and reliable. Happy debugging!