Search code examples
reactjsreact-hooksreact-router

calling react page from postman is possible or not?


We created a react js application. Problem: Not able to hit react URL from the postman to run component's function.

local URL: http://localhost:3000/rules/routine

Note: Above URL can be reached without login.

When we are calling a url from browser it's working however when we hit from a postman then it always returns public/index.html page but not the expected response.

So it is not calling the proper url http://localhost:3000/rules/routine.

Please find attached screenshots on below links

browser hit: https://prnt.sc/73gDWh4PiHgu

Postman hit: https://prnt.sc/fhVL78yaiATP


Solution

  • It's technically possible, and working it seems, but I suspect your expectations are a little skewed in what you think Postman will do or is capable of.

    Keep in mind that all React apps are effectively a single page app, even when they use a routing/navigation package like react-router. react-router is only manipulating the URL in the address bar in the browser window, the app is still running from the single location on a server where it's hosted, i.e. public/index.html.

    The servers hosting the app are configured to route all page requests, i.e. "http://localhost:3000/rules/routine" to the root index file, i.e. "http://localhost:3000/index.html" so the React app is loaded and can handle the "/rules/routine" internally.

    So from what I see here, the response from Postman is absolutely correct and what I'd expect to see. It made a request to the development server for a nested directory "/rules/routing" and the server responded with the root index.html file. When the browser makes this request to the development server and gets a HTML file back it loads and renders it, and in this case, it's your React app.

    Postman isn't a browser so it's not going to load the HTML response and do anything with it.