Redirect some API requests in a Website to localhost for Dev Test / Debug

Why do you need this redirecting?

Today most developers working with API & Web Applications. When we need to debug & dev testing an API that sending from a website. Our normal approach is taking the API call from the browser network tab to the Postman and change the request endpoint to localhost and required parameters. Dev Testing and Debugging is less effective in this way. Because we have to change multiple things in our API call. Sometimes we are running API for only one endpoint. But to test an entire flow with API calls is more time-consuming.

So, what if we can redirect some selected API calls to our local endpoints?

Yes, It’s possible, in a few simple steps you can get this done. I’ve selected Google Chrome for this.

Setup Chrome

Run Chrome without web security

You cannot do this redirect with some security concerns, so we have to run chrome without Web Security for this. You can do this from the below steps.

location

"C:\Program Files\Google\Chrome\Application\chrome.exe" — disable-web-security — user-data-dir="C:/ChromeDevMode"

Open the shortcut, If you can see as below, You are running Chrome without security successfully.

Setup “Requestly”

To do the redirecting, you’ll need “Requestly” plugin. You can take that from the below link.

Disable CSP

You’ll need to disable Content security policy headers to do this. You can do that from the below steps.

Redirect API Calls

Now I have a simple REST API created to simulate Soundcloud search using Flask. I’m going to redirect SoundCloud searches to my local API which will return a static response based on keyword.

Now original API call should be redirected to Local API as below.

Now you can see your SoundCloud search redirected to the Local API.

What you can do more …

This “Requestly” can be used to do much more things, changing API call parameters, headers and etc. Check other features if you are interested. Simply you can save time taken to stuck with some postman requests using this.

Cons.

We have to disable web security to do this, so you may have miss some real-world scenarios when you are doing tests using this. Also, if “Requestly” (or any other plugin which you are using to redirect) gathering your personal stuff that can be a problem. I couldn’t find any clue for that. If you know anything like that please share that with me too.

Thanks for reading, hope this will save a lot of your time. Please share your thoughts.

--

--

--

love programming, automate things, explore technical stuff and study Buddhism

Love podcasts or audiobooks? Learn on the go with our new app.

JavaScript — Using The Spread Operator (…)

Creating Awesome SPAs With React

Setting up a Maven Project on Eclipse in Linux Ubuntu Part 1

10 JavaScript Core Topics That You Should Know — part 2

A word on recursion.

The Node.js Community was amazing in 2017! Here’s the proof:

What Should A Selenium Interview Coding Test Include?

An Introduction to Three.js

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chandika Udaya Kumara

Chandika Udaya Kumara

love programming, automate things, explore technical stuff and study Buddhism

More from Medium

Magritte: An unknowable journey  —  Development of an immersive VR experience

Nobuya Kobori “New Official Releases for 359th Consecutive Days”

StreamDeck with WaveLink on macOS

How to “Step Up” in technology for 60+ generation eager to learn