REST API Experiments

In this document we explore how to fetch JSON data from the web and display it in various ways. We also make use of global variables, showing their content in an HTML template, and rendering blocks conditionally. Source of the data: https://alternative.me/crypto/fear-and-greed-index

Cryptocurrency Fear and Greed Index

In this first example we want to see last 15 days of the F&G index The data is downloaded from https://alternative.me API
  • we want to display the date on the x-axis
  • on the y-axis should be the value of the F&G index
  • what to display as the end-of-line label
  • outer width, in pixels
  • outer height, in pixels
  • we know the range of the y-axis (it's %) so let's indicate it
We download the data and process it with some javascript to feed the chart
Let's extract sentiment from the data, as a variable so we can use it later
Check below how we display the sentiment variable previously defined, via a HTML block
We can even use "if" branches to process and display things conditionally

Cryptocurrency prices

Now we want to display the current prices
  • we want price on x-axis
  • we want the name of the coin on y-axis
  • the left margin, in pixels
This time we fetch the API for the prices
We can use the map operation to keep only a subset of the properties
We want to show the cryptocurrencies sorted by price (descending)
Now we save this data because we want to re-use it in the next step too
At last we choose a table to list the cryptocurrencies
Let's specify which columns we want in the table, first an index
After the index we want the cryptocurrency name
And after the name, its price (notice how the $ currency symbol is added)
Let's load the previously saved data