A simple web-based bitcoin converter!
This project demonstrates the use of XMLHttpRequest, Fetch API, Promises and async/await. It fetches data from 2 different APIs: blockchain.info & fixer.io!
You can play around with this demo by replacing the script in
This is the default script. It supports a wide array of browsers, as it detects the feature(s) available and uses them accordingly.
This file is written in classical style, using the
XMLHttpRequest to fetch data from the APIs. The ‘classical doom of hell’ is visible here, along with multiple calls to the Error handling functionality. Here, the APIs have to be fetched sequentially.
This uses the
Fetch API (introduced in ES6) and the code is easier to read than before. The code also makes use of Promise chaining for easy maintenance. The APIs are fetched one after the other, mimicking calls to the
XMLHttpRequest in the previous
This uses the
Fetch API and
Promises. Instead of calling the APIs one after the other,
Promise.all is used to fetch the APIs in parallel.
async/await (introduced in ES8) is used to fetch the APIs one after the other. The structure of
async/await feels a lot cleaner and results in highly readable code.
async/await is used to fetch APIs concurrently using
Promise.all. Readable and easier code, makes it quite easy to maintain.