How to switch an API endpoint from one environment to another?

Web developers often want to test the local changes directly on production websites — be it for debugging a production bug or for testing local changes before shipping code to production. Tools like Source Maps or Local Overrides don’t often work for this setup. With Requestly, you can map your production endpoints to local endpoints on your machine in less than a minute.

Use Requestly to switch production API endpoint to local

Suppose you have the production APIs on domain.com , you can switch it to localhost:4001 using Requestly’s Replace rule. This will enable you to test your local changes on production.

  1. Install the Requestly browser extension and click on New Rule in the Top-Right.
  1. Next, Select the Replace String Rule from the list of rules. This should navigate you to the rule editor.
  2. Define for which requests you want the modifications to be made.

    eg: If you want to replace domain.com with localhost:4001

  3. Save the rule and test if the endpoint has been switched on the configured site.

Possible CORS issue

Most production systems have very strict CORS policies, only allowing the production site to access the resources served. It is likely that CORS error will occur if you switch endpoints.

If you face any CORS issue, then you need the create a headers rule bypass the CORS headers. Please find more details on how to solve CORS errors here.

This article was written by:

Picture of 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