Skip to content
Advertisement

Tag: fetch-api

Why does .json() return a promise?

I’ve been messing around with the fetch() api recently, and noticed something which was a bit quirky. post.data returns a Promise object. http://jsbin.com/wofulo/2/edit?js,output However if it is written as: post here is a standard Object which you can access the title attribute. http://jsbin.com/wofulo/edit?js,output So my question is: why does response.json return a promise in an object literal, but return the

How can I download a file using window.fetch?

If I want to download a file, what should I do in the then block below? Note: The code is on the client-side. Answer I temporarily solve this problem by using download.js and blob. It’s working for small files, but maybe not working for large files. I think I should dig Stream more.

Fetch: POST JSON data

I’m trying to POST a JSON object using fetch. From what I can understand, I need to attach a stringified object to the body of the request, e.g.: When using jsfiddle’s JSON echo I’d expect to see the object I’ve sent ({a: 1, b: 2}) back, but this does not happen – chrome devtools doesn’t even show the JSON as

Advertisement