Re: [whatwg] Questions about the Fetch API

From: whatwg <whatwg-bounces@lists.whatwg.org> on behalf of Juan Ignacio Dopazo <jdopazo@yahoo-inc.com>

> Would it be to crazy to get fetch(url).asJSON() to work? Either by not having fetch() return a promise (and return something that has a function that returns a promise for the headers) or by having it return a subclass of Promise that contains those utility methods?

In my opinion subclassing promises should not be done just for adding minor conveniences. It should be done for qualitatively new types of promises (e.g. cancellable ones), but arbitrary concepts should not become promise subclasses.

> Also, my question about the Request class is because I don't see a way to get a writable stream for the body of the request. It'd be nice if we had that for uploaders for example.

This is a very important question and we should look into solving it before the API settles too much.

To provide a clearer example of what Juan is talking about, in Node it is common to do something like


var req = http.request({ method: "POST", ... });

req.write("data1");
req.write("data2");
req.end();

// or even better

fs.createReadStream("file.txt").pipe(req);

We are doing a very good job IMO on preparing the spec for readable stream integration, with the FetchBodyStream scaffold. We need to spend similar effort preparing for writable stream integration. I would be happy to help spearhead this effort along with anyone else interested.

Received on Thursday, 10 July 2014 19:06:33 UTC