Writing isomorphic libraries
The holy grail of web development is the ability to write code not solely for the frontend or the backend but for both parts. Many frameworks and tools try to give us this capability.
To be accessible to multiple platforms, we not only need to ship multiple variants of our code but also only use APIs that are available on all supported platforms. For instance, if you want to make an HTTP request, then using fetch
would be the right call for modern browsers. However, fetch
was not available in less recent versions of Node.js. Therefore, you might need to solve this differently.
In the case of HTTP requests, there are already isomorphic libraries available – that is, libraries that will just do the right thing depending on the target runtime. You should only depend on these libraries.
Isomorphic fetch
The HTTP request problem can be solved in many ways – that is, by choosing an isomorphic library such as axios
or isomorphic-fetch...