Fetch with ReadableStream as Request Body
We’re working on making this work, see https://github.com/whatwg/fetch/pull/425 for the PR to the Fetch Standard. Once that is done you can expect this to make its way into browsers (slowly).
We’re working on making this work, see https://github.com/whatwg/fetch/pull/425 for the PR to the Fetch Standard. Once that is done you can expect this to make its way into browsers (slowly).
Add the following line in addition to your current bodyParser app.use() right before: app.use(bodyParser.json()); This will enable bodyParser to parse content type of application/json. Hopefully that helps!
Overriding the Content-Type request header is not allowed for no-cors requests. Change the mode to cors. (You won’t be able to read the response without doing that either).
Answering my own question. I find it pretty enraging that this is a “working as intended” behaviour of Safari, though I understand their motivation. XHR (and presumably native fetch when it lands natively) does not support the setting of third-party cookies at all. This failure is completely transparent because it is handled by the browser … Read more
The status code is the status property on the response object. Also, unless you’re using JSON with your error responses (which some people do, of course), you need to check the status code (or the ok flag) before calling json: fetch(`${baseUrl}api/user/login`, { credentials: “include”, // ¹ See note below headers: myHeaders }) .then(function(response) { console.log(response.status); … Read more
After much head banging, I solved this issue by setting the ‘credentials’ property of the request to ‘include’. I was under the impression that this only controlled the sending of cookies to the server on fetch requests, but apparently, at least in the implementation I am using, if not set it also means that cookies … Read more
400/500 is not an error, it’s a response. You’d only get an exception (rejection) when there’s a network problem. When the server answers, you have to check whether it’s good or not: try { let response = await fetch(‘not-a-real-url’) if (!response.ok) // or check for response.status throw new Error(response.statusText); let body = await response.text(); // … Read more
The way promises works mean you’ll need to handle the responseJSON inside the handler for then(). Due to the asynchronous nature of requests the outer code will already have returned by the time the promise resolves. It can be hard to get your head around at first, but it’s much the same as a “traditional” … Read more
Your code mixes continuation callbacks and Promises. You’ll find it easier to reason about it you use one approach for async flow control. Let’s use Promises, because fetch uses them. // Refactor getStudents and getScores to return Promise for their response bodies function getStudents(){ return fetch(`api/students`, { headers: { ‘Content-Type’: ‘application/json’, ‘Accept’: ‘application/json’ } }).then((response) … Read more