Simulate Fake response status codes using Requestly

This article will take you through how to use Requestly to simulate fake 404, 500 response status codes and test your frontend app without changing anything in your codebase. There are two possible ways to solve this using Requestly:

If you want to simulate a different status code for network traffic in Android apps, use our Android Debugger

Using Desktop App

You can use any MITM proxy to intercept the request and simulate the status code. However, using Requestly Desktop App, it is possible in a single step.

Steps

  • Go to Rules Tab and Click on New Rule
  • Select Modify Response
  • Define the exact URL (or Pattern) and define the status code. That's it.

Modify Response Status Code Rule

Here's a step by step video demo explaning same.

Download Requestly Desktop App from here

Using Browser Extension

Requestly Browser Extension can simulate different status codes on an API by redirecting the actual API to a mock API using Requestly's Redirect Rule.

Mock Server

Steps

1. Create a mock API using Requestly

Requestly has a Mock Server capability to create a Mock API response. Here are the steps to create one.

Example mock Simulating 500 status code- https://app.requestly.io/mock/aIfQd7toGFUMCL0PZDrc

Requestly mock server handles the CORS headers automatically so that the browser does not block the cross-origin requests.

2. Redirecting actual API endpoint to the Mock Server endpoint.

  • Setup a redirect rule to redirect the actual API to the requestly mock API.

Redirect Blinkit Search API to a mock API simulating 404 status code

Redirecting Blinkit Search API to a mock API simulating 404 status code

3. Removing Content-Security-Policy Headers

Sometimes redirection to mock API won’t work due to Content-Security-Policy- connect-src directive, which restricts the URLs loaded using script interfaces.

You can use the Requestly marketplace rule to bypass this, which has a prebuilt rule to remove the content-security-policy header. Thats it.

Requestly Marketplace

Download Requestly browser extension from here

I hope this empowers you to do robust testing of your frontend app/website by simulating different API behaviours.

Further Resources:

Happy Debugging!

By @nafees87n

Get to know Requestly

Become a 10x developer by using Requestly in your development & testing workflows.

No spam guaranteed :)