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:

Sagar Soni

Sagar Soni

Sagar, the co-founder and CTO of Requestly, has been pivotal in shaping the company's vision and product trajectory. With over a decade of professional experience, he has been affiliated with renowned companies like Google, Adobe, and Grofers.

Share this article:

You may also like