Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change fetch method to a string #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tom-sherman
Copy link
Contributor

@tom-sherman tom-sherman commented Dec 21, 2021

Relates to #30 and #38

The variant here wasn't gaining any extra type safety and introducing a cost to the bindings where none was needed.

method accepts any arbitrary string and while it's true that some HTTP methods are specced to be in uppercase, the fetch API will normalise them for you.

@TheSpyder
Copy link
Owner

I'm a little on the fence about this one. While yes the variant wrapper is somewhat of a type flex, it's also nice to have the compiler guarantee that if the method needs to be set, for the vast majority of use cases the string is spelt correctly.

Could we make the default method a polymorphic variant, which achieves the same goal, and have some other way to set the method that takes a string for those edge cases? I'm not sure exactly how this would work short of a duplicate @obj binding, it just seems like a nice compromise.

I'm adding this to the 2.0 release since it's a breaking change. I might start a feature branch for 2.0 so we aren't leaving your PRs open for months; one of the nice things about the way ReScript compiles is dependencies can point to a git branch instead of NPM and still work perfectly.

@tom-sherman
Copy link
Contributor Author

tom-sherman commented Dec 22, 2021

Could we make the default method a polymorphic variant, which achieves the same goal, and have some other way to set the method that takes a string for those edge cases

@TheSpyder I'm not sure this would work with Request.method, that would still need to return a string which seems inconsistent. The other option is of course to use a polyvar with encode/decode functions, but that doesn't solve the original problem of trying to reduce conversion code.

@TheSpyder
Copy link
Owner

ok, fair point.

Copy link
Collaborator

@spocke spocke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we had convenience functions for common methods like makePost, makeGet, makeDelete some of those could also skip having a body property since you can't send that into a get request for example and it would also avoid the weird case where method is a poly variant as input and a string as a property on the object.

It would make the bindings a bit larger since all the properties would have to be duplicated between these functions. Not sure if it's worth it though since having the wrong method will likely not be missed if you make any form of rest api call since it will simply not work.

@tom-sherman
Copy link
Contributor Author

some of those could also skip having a body property since you can't send that into a get request

Huh, TIL the fetch API enforced that. It's not something that bs-fetch or TypeScript enforces - I'm guessing because it's pretty difficult to make that mistake without your program not working as you mention.

@TheSpyder
Copy link
Owner

I haven't forgotten about this, but we're getting fairly close to a 1.0 release candidate. Once I'm happy 1.0 is stable (it won't release until ReScript 10 does) I'll make a 2.0 branch and we can start merging PRs like this one to experiment with API changes.

@TheSpyder
Copy link
Owner

1.0 seems fairly stable but it might be another month before I have time to start the 2.0 branch. Work has been too busy in the lead up to TinyMCE 6.0 to spend any time on this, and I've had a log of personal stuff to deal with so I can't make time in the evenings for it.

@TheSpyder
Copy link
Owner

Sorry for letting this sit idle for so long. I've had a very busy time both in work and personal life.

ReScript v10 hit alpha today, so I'll make time soon to wrap up the planned activities in version 1.0 and we can begin breaking APIs in earnest while we play with the new features.

@TheSpyder TheSpyder force-pushed the main branch 5 times, most recently from fe0f2e9 to 7f2cf0a Compare May 22, 2024 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants