This is a simple example of an advanced functionality of Valkyrie Engine, where you will learn how to pull data from the web and display it in your scene.
We will use a publicly available API that requires neither registration nor API key and displays parameters of various cryptocurrencies: https://www.coinlore.com/cryptocurrency-data-api 1
Here is an example of the GET request method I am going to use for illustrative purposes: https://api.coinlore.com/api/ticker/?id=90 2 This request will return the following properties and values:
id | “90” |
---|---|
symbol | “BTC” |
name | “Bitcoin” |
nameid | “bitcoin” |
rank | 1 |
price_usd | “11946.72” |
percent_change_24h | “0.12” |
percent_change_1h | “0.99” |
percent_change_7d | “14.00” |
market_cap_usd | “213235242029.04” |
volume24 | “17003508444.32” |
volume24_native | “1423278.92” |
csupply | “17848859.00” |
price_btc | “1.00” |
tsupply | “17848859” |
msupply | “21000000” |
Now let’s implement this in Valkyrie.
I start with a new level:
Then do a bit of cleanup:
I add a Text entity that I name “Bitcoin display”, where I will display the USD value of a Bitcoin:
Notice that in the Text entity, you have a “text” property which will be used to receive the bitcoin value later on:
I add a DataTable entity that will receive all the data pulled from the API:
Now we have 2 actions to add to the Timeline and we are all set.
First I drag&drop a DataTableReadURL action, which will allow me to call the API, onto the DataTable entity:
I then set the DataTableReadURL properties:
Lastly, I drag&drop the entity EntitySetProperty, which will allow me to change the properties of my Text entity, onto the DataTable entity:
I then set the EntitySetProperty properties:
This is it, I just created an app that will retrieve the USD bitcoin value in real-time from a web API:
Note that it can take a little time before the USD value of the bitcoin is refreshed. These parameters depend on the API provider.
You can do any HTTP GET request which receives a flat JSON object as response.
If you need to process complex APIs (APIs that respond with deep hierarchies or arrays), you will need to create a small proxy server to provide a clean HTTP interface to your Valkyrie application.
Feel free to ask for help in our Discord server if you need help with getting your data in Valkyrie.