Fetch is not a complete implementation
MercerK opened this issue ยท 1 comments
When looking into fetch, it doesn't seem to be a complete feature. It barely functions, if that.
There is core.fetch
that accepts a single parameter. I'm assuming it only defaults to GET
and nothing more.
- How do you customize this?
- How do you select different methods, like GET, POST, etc?
- How do you add headers?
- How do you follow redirects?
Oddly enough, fetch doesn't work the way you expect it to. Fetch doesn't do anything other than creating an object. If you want to do something with fetch, you need to do fetch().json()
or fetch().read()
, which goes against the grain of expectation when working with fetch on JavaScript.
The other portion is async
. I'm not sure how you are supposed to do async
with fetch and have it work. It seems to pass it off into a desync
object, which tries to get another context to run it. But I believe this is failing as it expects async.js
to exist and depending on how folks build their environment, that file may not exist on prod.
Then there is error handling.
[22:45:06 WARN]: An error occured while attempting to execute a task!
[22:45:06 WARN]: Server returned HTTP response code: 400 for URL: http://localhost:3000
How do we handle errors correctly in this case? It seems to be only throwing a string and not the key object we need to work off of.
I tried implementing my own at the JS level and so far, that fails fairly early on due to HttpRequest.newBuilder().uri(new URI(uri))
.
When looking at the sister library, I found this:
-
Java implemented fetch: https://github.com/Dysfold/craftjs/blob/master/java/src/main/java/fi/valtakausi/craftjs/api/CraftJsContext.java#L243
-
On their JS side, they have: https://github.com/Dysfold/craftjs/blob/master/core/src/fetch.ts
As this isn't feature complete, I'm worried that this is creating a blocker for other developers, as they can't do even basic functionality with fetch.