rescript-webapi icon indicating copy to clipboard operation
rescript-webapi copied to clipboard

Update Fetch API

Open TheSpyder opened this issue 4 years ago • 4 comments

The new fetch API is just a copy of bs-fetch with a bit of re-arranging to separate out the inner modules (this aids tree shaking).

There are far better ways to do most of this in ReScript now; the API would benefit a lot from records-as-objects and polymorphic-variants-as-strings. Unfortunately, to a tree-shaking benefit from this the old Functor approach has to be removed.

As much as I'd like to update the API, there are over 1300 repositories depending on bs-fetch. Now that I know ReScript 10 will break their code, I want to start by making migration as seamless as possible for them.

So I'm tagging it as release 2.0 for now. If we have time for both the API update and a migration guide before ReScript 10 is released we can consider merging it in the 1.0 release.

TheSpyder avatar Sep 23 '21 10:09 TheSpyder

Experiments here https://github.com/tinymce/rescript-webapi/compare/fetch-newapi (this will contain all changes until the core Fetch PR is merged)

TheSpyder avatar Sep 23 '21 10:09 TheSpyder

Perhaps we can take some inspiration from the work @Kingdutch has done: https://github.com/Kingdutch/reason-fetch

It's gone in the direction of reason-promise, which is fair enough, but that's not suitable for Webapi. There are however many good ideas there that we can borrow.

TheSpyder avatar Sep 23 '21 11:09 TheSpyder

Request from @ka-work in #33 - generalise Url.createObjectUrl to work for both Blob and File. Perhaps with some sort of blob_like type, similar to element_like.

This isn't specifically fetch related, but it's fairly close and I think the opportunity for a breaking change is a good time to do it.

TheSpyder avatar Oct 29 '21 08:10 TheSpyder

I guess that make sense we would have to make some bindings for FileReader that I think takes both Files and Blobs for example. The createObjectUrl takes a media source though that isn't a subclass but that could be it's own function createObjectUrlFromMediaSource or something.

spocke avatar Oct 29 '21 09:10 spocke