Use Cases

5

min read

Simulate Fake response status codes using Requestly

Nafees Nehar

This article will take you through how to use Requestly to simulate fake 404 and 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:


format-quote-open

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

Using Desktop App

Any MITM proxy can intercept the request and simulate the status code. However, using Requestly Desktop app, it is possible in a single step.

  1. Go to Rules Tab and click New Rule.
  2. Select Modify Response.
  3. Define the exact URL (or Pattern) and define the status code and Save the rule
Modify Response Status Code Rule
Modify response to simulate 404 code

Here's a step by step video demo explaining the 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
Requestly redirects the requests and response from API server to Mock server

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.

  1. Create a new mock API here: Create Mock Server
  2. Set the status code you want to simulate (404, 500 …).
Mock API sending 500 status code

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

format-quote-open

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

Redirecting the actual API endpoint to the Mock Server endpoint.

Set up 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

Removing Content-Security-Policy Headers

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

You can bypass content-security-policy header using Requestly's built-in template.

Requestly Marketplace
Requestly Templates

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

SHARE THIS POST

Keep reading

All Posts

Go next