KristjanESPERANTO / MagicMirror-3rd-Party-Modules

This project provides an overview of all MagicMirror² modules and puts the modules through a few tests.
https://kristjanesperanto.github.io/MagicMirror-3rd-Party-Modules/
MIT License
17 stars 5 forks source link

Built-in Fetch documentation? #25

Open dathbe opened 6 months ago

dathbe commented 6 months ago

The recommendations page recommends replacing functions like axios and node-fetch with a built-in fetch function. But I can't find documentation on how the fetch function works. (changing axios.get(url) to either fetch.get(url) or fetch(url) does not work). Where can I find the documentation?

In general, and I know this is a work in progress, it would be good to provide links to some documentation or instructions when substantive recommendations are made.

KristjanESPERANTO commented 6 months ago

The main advantage of the fetch API is that it works in the browser as well as in node without external packages. It is relatively new, but is now supported by all browsers and node.

In most cases it can replace the other variants (axios, request and node-fetch). I have already converted some modules accordingly. If you like, show me a module that you would like to convert and I'll take a look at it :slightly_smiling_face:

Here is a documentation of the fetch API:

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

provide links to some documentation or instructions

Yes, that would be nice. I think especially for fetch and for ESLint that would be helpful.

dathbe commented 6 months ago

I have a private module that I need to replace request in. But as far as public modules:

KristjanESPERANTO commented 6 months ago

An example of switching from XMLHttpRequest to fetch you can see in this commit https://github.com/dathbe/MMM-CustomMessage/commit/dc74297f9ba512d6f8f169bb10b23a54406c5497.