Logo

Query & Submitting Request for External Data

Query

A query is a request for real-world data on behalf of users' smart contracts which should be written and submitted in a special format according to utilized data source. Subsequently oracle data carriers can recognize users' requests and respond them.

Parsing Helpers

Responses of requests are in the format of JSON, XML or HTML. Thus in order to extract an exact element, for example in a JSON API response, such raw results should be parsed, initially. In order to parse such data, parsing helpers should be applied to it. Examples:

  • JSON Parser: Bridge built-in JSON parser can parse and extract a specific element from JSON format results if the request is sent from users' smart contracts using following format:

    json(https://api.kraken.com/0/public/Ticker?pair=ETHUSD).result.XETHZUSD.p.1
  • XML Parser: Bridge built-in XML parser can parse and extract a specific element from XML format results if the request is sent from users' smart contract using following format:

    "xml(https://samples.openweathermap.org/data/2.5/weather?q=London&mode=xml&appid=439d4b804bc8187953eb36d2a8c26a02).current.city.country"
  • HTML Parser: This format can be used for HTML scraping purposes using XPATH language. Requests should be sent using following format:

    html(https://wikipedia.org/).//*[contains(@class, 'central-textlogo__image')]/text()

    In continuance, it will be discussed that how one can use above formats.