SteemData WebAPI Example #1 - Posts Metadata Fetching And Display

in #utopian-io7 years ago

Continuing my fascination with SteemData WebAPI by @furion I created a first webpage which really does something useful.

In fact, this page is a basic example of the usage of https://webapi.steemdata.com/Posts endpoint.

See it in action here: http://steemgnome.com/steemdata_example_aggregator_01.html

image.png


What this page does?

It fetches json data from the following hardcoded endpoint:

https://webapi.steemdata.com/Posts?where={"author":"ervin-lemark"}&sort=-root_comment&page=1

It displays a table of fetched data with following attributes used:

  • image thumbnail derived from items[x].json_metadata.image[0],
  • title with url : items[x].url and items[x].title,
  • the category with the link to it: items[x].category
  • pending or actual payout value:
            if (items[x].pending_payout_value.amount != '0') {
        txt += '<div class="divTableCell">Pending: ' + items[x].pending_payout_value.amount + ' ' + items[x].pending_payout_value.asset + '</div>';
      }
      else {
        txt += '<div class="divTableCell">Author: ' + items[x].total_payout_value.amount + items[x].total_payout_value.asset + ', Curators: ' + items[x].curator_payout_value.amount + ' ' + items[x].curator_payout_value.asset + '</div>';
      }
  • net votes: items[x].net_votes
  • it is capable of rude pagination (previous/next)

All the above references to items[x] are based on data._items collection returned by the call.


Tutorial About The Page Is Coming

I will create a tutorial (or two) where following steps will be explained:

  • how to fetch json data from an external domain with pure javascript
  • how to read and iterate through the fetched collection
  • some additional tips and tricks

Be aware that I am relearning the trade of javascript programming. My skills are rusty at best. Too many years of PL/SQL coding :)


Next steps

  • to create a good looking front page and loose table-like div display,
  • to add author parameter and form field so you can choose which author's posts to display
  • to add frontend parameter and form field so you can decide on which Steem frontend the article is displayed
  • to create proper pagination so you could jump to last page or any page in between
  • to add sort parameter to switch between newest / oldest sorting.

Can you imagine this last item in action? Yes, you could list your old posts first!


Proper Github Repository

I have created a new git gub repository at https://github.com/ervin-lemark/steemdata-examples. This repository is not a fork of an existing official repository with the SteemData usage examples. In it, I will develop and maintain various short scripts showing the power of SteemData WebAPI. Feel free to check it out.

The example in question here is already available at the repository.


History Of SteemData WebAPI and javascript Related Articles

  1. How To Quickly Get All Data About Your Articles With Help Of SteemData WebAPI
  2. Posting with steemjs #2 - checking tags, community and app
  3. Rudimentary test of posting with steemjs



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

I think I have a first issue for you. The "created" and "category" columns headers are swapped.

Clipboard_data.png

You can contact us on Discord.
[utopian-moderator]

Thank you very much.

You are right about the swapped headers, of course. This is the most common programer's error - copypasting and not reading after yourself :)

I will fix it immediately. I've noticed an issue or two myself. One is the payout check. I should check both the date and the payout amount to determine if the payout is due or already done. Now, when the post in brand new, the .pending_payout_value value is 0 and the code outputs the wrong label.

Thanks again, I appreciate it!

Hey @ervin-lemark I am @utopian-io. I have just upvoted you!

Achievements

  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.035
BTC 90748.39
ETH 3148.78
USDT 1.00
SBD 2.98