Does fetch follow HTTP 30x redirects?
Normally, fetch transparently follows HTTP-redirects, like 301, 302 etc.
The Fetch API allows you to asynchronously request for a resource. Use the fetch() method to return a promise that resolves into a Response object. To get the actual data, you call one of the methods of the Response object e.g., text() or json() . These methods resolve into the actual data.
In response to a REST API request, the Nest API server returns a redirect. The REST client detects the redirect and requests the page that the client was redirected to. Some HTTP implementations do not forward the Authorization header to the redirected URI, and this results in a 401 Unauthorized error.
fetch() allows you to make network requests similar to XMLHttpRequest (XHR). The main difference is that the Fetch API uses Promises, which enables a simpler and cleaner API, avoiding callback hell and having to remember the complex API of XMLHttpRequest.
Yes. Check this.
Checking to see if the response comes from a redirected request is as simple as checking this flag on the Response object.
if (response.redirected) {
//...
}
You can disable it:
fetch("awesome-picture.jpg", { redirect: "error" }).then(function(response) {
//some stuff
}).then(function(imageBlob) {
//some other stuff
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With