One of my very obvious knowledge gaps is HTTP redirects and what role they play when working with AJAX requests and APIs. I've read this MDN guide on redirects. I know that redirects return a 3xxstatus code and provide a Location response header. Furthermore, the MDN guide states this:
When browsers receive a redirect, they immediately load the new URL provided in the Location header.
This makes sense to me when dealing with HTML directly (e. g. submitting a form and receiving a redirect after).
When dealing with API's it all becomes a little fuzzy. I've read this quora post where most participants say that redirects don't play any role in REST. When I tested this, the browser made a request to the URL provided in the Location header but did not navigate to it. Instead, I would just load the HTML response if the location was on the same origin and fail with a CORS error for different origins.
I'm currently trying to solve this problem: I send an AJAX payload to an API and want to redirect the user to a different domain (& origin) upon completion. My question is this: Do I send back the redirect URL as a payload and navigate the user to the new origin with the window.location object (javascript) or can this be handled with a HTTP redirect?
I'd love some help.