In this section is an overview of coding exercises and references
An API stands for Application Programming interface and allows you to fetch or get data from an open source of data on the web. The data is return to you in JSON format. Some API's require you to sign up and even pay while others are free. Some have limits on the number of fetches you can make per day. Some API's are more powerful then others and allow you to refine the data results you get using special commands.
There is an API for almost anything including:
Weather
News
NASA star tracking
Library books
Shark attack data
CFS incidents.
It stands for JavaScript Object Notation. It structures data consistently with a property name and a value. Here is an example:
'{"name":"John", "age":30, "car":null}'
When we request the data is formatted as a string and needs to passed back into JSON.
Fetching data using ansyncynous functions is a great tool and allows the large sets of data to be grabbed before completing other function in your program. Here is a basic example using promises. Promises make sure one command is completed before starting the next. We use a try an catch block for error handling. You will notice the function starts with async which indicates the function needs to fully complete before completing other parts of your code.
var data;
async function fetchAllData() {
try {
const response = await fetch('https://public.opendatasoft.com/api/explore/v2.1/catalog/datasets/global-shark-attack/records?where=country%3D%22Australia%22%20OR%20country%20%3D%20%22AUSTRALIA%22&limit=100');
data = await response.json();
} catch (error) {
console.error(error);
}
}
4. What can I do with this data?
Once you have fetched the data you can use it in your application to do things like:
Create graphs and tables of results
Map locations on a map and make interactive applications
Sort and organise the data
Use the data to present results based on user feedback