<aside> 💡 In this chapter, we will understand how the Elrond API works and how you can use it to get useful information from the blockchain
</aside>
When you go to a weather forecase website, it serves you with the latest weather data. This data is dynamic and constantly changing, hence it is not baked into the weather website. Instead, the weather website likely queries a so-called REST-API to get the freshest data. This following diagram should illustrate this:
graph TD
User --> |Visit| A(Weather Website)
A --> |Ask weather data| B(REST API)
B --> |Ask raw weather data|C(Database)
C --> |Return raw weather data|B
B --> |Convert data|B
B --> |Return weather data|A
A --> |Prepare data for presentation|A
A --> |Show weather data|User
A REST-API is thus an interface that responds to requests. There are multiple types of REST-Requests (GET, POST, PUT, PATCH, DELETE, …), but we will only focus on the GET type in this tutorial.
As the name implies, a GET-Request gets you data. Nothing more, nothing less. Back to the weather example, let’s say the weather website wants to get the temperature in Ohio between 11-12 AM. A fitting request could look like this:
GET <https://api.weather-website.com/forecast/ohio?from=11&to=12>
Let’s break it down step-by-step:
https://api.weather-website.com
is the host of the API. For the Elrond API, the host is https://api.elrond.com/forecast/ohio
is the path of the request. Depending on the path, the API will serve different data. For example, when changing the last segment of the path from ohio
to new-york
, it would instead return weather data for New York?from=11&to=12
are the query parameters of the request. Here you can usually fine-tune the response. In our example, we want to narrow the results by only returning us weather data between 11 and 12 AM. This can save data, since otherwise we would request data that we don’t even need.Now that we understood the basics, let’s move to https://api.elrond.com and have a look at the Elrond API!
As we can see, we have plenty of paths (endpoints) to choose from. Every endpoint serves different data. Let’s see if we can extract something meaningful here!