Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
HTTP redirects when working with REST APIs

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.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda