API 4. Some tests with different API’s

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

The above image is for LinkedIn viewers as the API doesn’t seem to fire when viewed from linkedIn. Go here to see web page where the API displays the information.

There is also an Extended page with weather & forecast for Wellington, NZ, London, UK & Boston, Ma, USA. Find it here.

Output from API Call

The API GET call output above is created from the script below (note leading < deleted so it shows as text, correct Javascript code written below) . On opening this web page the Javascript runs and a query to yahooapis.com gets weather data about Boston Massachusetts. It then displays the data  on the screen using the javascript document.write() function. This is an example on the Yahoo website here.

You open your page and it updates with the latest information. This could possibly be combined with the dataTables to pull the latest data from an API and display it in a tabular manner.

script>
var callbackFunction = function(data) {
var wind = data.query.results.channel.wind;
var dateTime= data.query;
document.write(“Date/Time of information = “+ dateTime.created.bold());
document.write(dateTime.created);
document.write(“
“);
document.write(“Wind Chill in Boston MA now in Fahrenheit = “);
document.write(wind.chill);
document.write(”
“);

document.write(“Wind Direction in Boston MA now in degrees [0 =N,90=E,180=S,270=W] = “);
document.write(wind.direction);
document.write(”
“);

document.write(“Wind Direction in Boston MA now in MPH = “);
document.write(wind.speed);

document.write(“Wind Direction in Boston MA now in degrees [0 degrees =North] = “);
document.write(wind.direction);

document.write(“Wind Direction in Boston MA now in MPH = “);
document.write(wind.speed);
};
/script>

script> <src=”https://query.yahooapis.com/v1/public/yql?q=select wind from weather.forecast where woeid in (select woeid from geo.places(1) where text=’boston, ma’)&format=json&callback=callbackFunction”> /script>

Postman view of the Get request to the API

This is the Postman view of the Get Request. Interesting that a JSON format was requested but an XML output in the bottom pane.  The original Javascript only had the wind  “Chill” and I decided to add the wind “direction” and “speed” as the data was available. Also I added the date/time to display too.

I quite like this process as you get the data in a JSON or XML format and use Javascript to display the information on your page. JavaScript is doing the post-processing from the Get request. Much better than converting the JSON to CSV then on to something else. And it displays on the page nicely, although I think I need to investigate how to format the data in a better manner. The great thing is all the processing is done within the web page.

NIWA data

NIWA is the National Institute of Water and Atmospheric Research. We’re New Zealand’s leading supplier of atmospheric, freshwater, environmental and marine science services.

So I joined their service to get information from their site. This is more like a DataBase Query process rather than an API .

You can export the data as Excel, HTML, Tab or space delimeted files. So really just a straight Search & Download from a database, even though its on the https://www.programmableweb.com/ as an API.

The Guardian  & Twitter API’s

I got API keys for both of these when I was testing out Orange Text Data  Mining . So I thought I would run them both.

For the Guardian I did a search on “Brexit talks” and got a number of articles with URL’s to the articles. With the returned JSON this could be scripted like the Yahoo weather data above to display using JavaScript on a web page or it could be converted to a CSV file for use elsewhere.

The Twitter data I did a query on” Pakistan election: Imran Khan”. This I displayed as HTML data and Cut/pasted it to Notepad++ where I saved it as a .html doc and then displayed the results to a Browser.

And in the browser it just looks like a Twitter page showing the tweets about the issue.


Here we can just embed the Twitter Get request into the web page.

Click on link:
Pakistan election: Imran Khan

End comment

I noticed, while writing this post that the save/view process was extremely slow. Since it is finding a GET request, heading off to get that data, then displaying it on the page, it takes time.

So I think the moral to the story is to minimise what data you are calling from the API so that it downloads fast. Pulling redundant information through the API will slow the process, and it is unnecessary as you are not using it to display on the page. This is where the Postman App comes in useful as you can refine your Get request to be quite specific so that you minimise the data transfer to only the essential information that you require.

I feel I am starting to get to grips with the API’s now. I can, with the help of the postman app play with the API data with more confidence. Still a way’s to go yet though.

Add a Comment

Your email address will not be published. Required fields are marked *