Simulate Different API status code using Requestly

This article will take you through how to use Requestly to simulate different API status codes and test your app.

Using Browser Extension

Requestly Browser Extension can simulate different status codes on an API by redirecting the actual API to a mock API.

The mock API simulating the desired status code is hit instead of the actual API. It is done using the redirect rule of requestly.

Mock Server

Create a mock API using Requestly

Requestly has a Mock Server capability to create a Mock API response.

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

Redirecting the 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

Redirect 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 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 is a prebuilt rule to remove the content-security-policy header.

Requestly Marketplace

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

Further Resources:

This feature will soon be available on the desktop app. Stay Tuned.

Happy Debugging!

By @nafees87n

Get to know Requestly

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

No spam guaranteed :)