Posting JSON to html

Hello,

I would like to make a live price chart in HTML that pulls the prices from https://api.nomics.com/v1/prices?key=2018-09-demo-dont-deploy-b69315e440beb145

How can I do this?

Thank you

Hi there!

It would help to know a little more about what exactly you are trying to accomplish. For example, when you say chart, are you interested in some sort of visual graph or table? Are you planning to use all of the prices, a particular subset or just one? Are you creating something from scratch, or are you integrating into something existing? If you using an existing framework, there may even be ways to visualize data easily through it.

If you’re planning a graph from scratch, there are many charting libraries out there that can work with JSON data that is provided through our API. Here are a few:

Each of these have their own instructions on configuration and use, but effectively you’ll need to:

Some of this might take a bit of work to get setup if you haven’t done this before, but there are many resources and tutorials online that can help get you off the ground. If you have any more specific questions on how to use this data, I’m also happy to help.

1 Like

Hi,

I appreciate the helpful post. I am looking to make a custom table from scratch that looks something like this:
//**pricechart.php

Coin Price
BTC (BTC price)
LTC (LTC price)

Then I would like to create a function that looks something close to:

//**page1.php
form action=“page2.php”>

input id=“Sending”> select which type of coin you would like:

select>
option value=“BTC”>BTC
option value=“LTC”>LTC
/select>
/input>
please enter the amount you would like:

input id=“amount”>
input id=“Receiving”>Please select the type of coin you are sending:
option> BTC
option>LTC
/input>
button value=“submit”>Submit

//** page2.php

Echo “please send “ $sending/$receiving to
$address

I apologize for the rough description.

Thank you

I have to admit that I haven’t actually worked with PHP in many years. I also have to say that I am not going to write your entire application for you, but will help get you started pulling data from our API.

I put together the following function that will download the prices list, iterate over the list and create a HTML table with Currency and Price. Again, I am not a PHP dev, so the following may not follow best practices, conventions and may even be considered bad (you probably shouldn’t use this for your final code):

<?
function make_price_table() {
  $url = 'https://api.nomics.com/v1/prices?key=2018-09-demo-dont-deploy-b69315e440beb145';
  $json_string = file_get_contents($url);
  $currencies_array = json_decode($json_string, TRUE);

  echo "<table>
    <thead>
      <tr>
        <th>Currency</th>
        <th>Price</th>
      </tr>
    </thead>
    <tbody>";
  foreach ($currencies_array as $currency){
    echo "<tr>
      <td>{$currency["currency"]}<td>
      <td>{$currency["price"]}</td>
    </tr>";
  }
  echo '</tbody>
  </table>';
}

make_price_table()
?>

I hope this gets you off the ground. Good luck!

Hi,

This is a very helpful post.

Thank you