scala-js/scala-js-dom

Fetch request body as ReadableStream

ptrdom opened this issue ยท 4 comments

According to the specs, Fetch should be able to handle ReadableStream as request body. Implementing this would likely result in some changes to ReadableStream and ReadableStreamController facades - ReadableStream needs a constructor that implements the underlyingSource, which allows interaction with ReadableStreamController, and ReadableStreamController should not have its own constructor, as it is constructed by ReadableStream during its construction.

If implementing this would be approved, I could give it a shot.

References:

Thanks for this! ๐Ÿ‘ to these changes, the goal is to match the spec so a contribution for this would be very welcome ๐Ÿ˜

However, just so you are aware ... I recently implemented a Fetch-based client as well in http4s-dom and tried using a ReadableStream in the request body, but was dissapointed to learn that many browsers have not implemented this feature for requests. See:

https://caniuse.com/mdn-api_request_request_readablestream_request_body

I have just realized that also, while playing around with possible new version of the facade ๐Ÿ˜ž. I guess it still makes sense to have the upgraded facade in case someone might find some use for natively available streaming implementation and to prepare for eventual browser support for ReadableStream in Fetch request body.

I will start working on the PR then.

Thanks! The enhancements for ReadableStream in general are a good idea, and even though browsers have not implemented it, there are other environments that have, such as Cloudflare Workers (serverless):
https://developers.cloudflare.com/workers/runtime-apis/request#requestinit

Good news, it seems that Chrome will finally be supporting this:
https://developer.chrome.com/articles/fetch-streaming-requests/

Hopefully other browsers will follow suit.