Note: You should use Kali Linux for this lab!

An API (Application Programming Interface) is a set of rules that allows different software programs to talk to each other. It acts as a bridge, letting one app request data or features from another. To help developers build these connections easily, APIs usually come with clear documentation and ready-to-use code tools.

In this lesson, we’ll write a program that utilizes public APIs to access National Weather Service data and print out real-time alerts.

If you are interested in exploring this topic on your own, a Google search for list of public APIs' will turn up many different results. For now, let’s start with this list.

<https://github.com/public-apis/public-apis>

Search that page for the ‘National Weather Service’ and click the link.

Untitled

Many of these services require an ‘API Key’, which means you have to sign up and register. These websites will provide you with a secret value (API Key) that you must use each time you make a request to the service.

The National Weather Service doesn't require an API key, which makes this lesson easier. (Signing up for an API key with any site on this list is usually a simple matter of logging in to the website and saving the unique value they provide. It works like a password. )

One common way to use APIs is through web requests via a script or program running on a user's computer. APIs are commonly accessed over HTTP/HTTPS via URL Parameters. The National Weather Service API is simple enough and is a good example of how API access works.

On the NWS site, let’s go to the ‘Specifications’ tab and see what’s available.

Untitled

As we can see, they provide an ‘API Endpoint’ of /alerts that will provide us with data. Let’s try the first API endpoint they offer (/alerts). Go to this URL:

<https://api.weather.gov/alerts>

Tip: Once you go to the alerts/ endpoint, select ‘View Page Source’ if the information isn’t automatically expanded.

Untitled

JSON (Key Sec+ Concept) is commonly used to store and retrieve data on the web. We’re looking at a series of *key: value* pairs. A JSON beautifier makes it easier to see how the data is structured. Let’s copy and paste all the data from this API endpoint into the website below:

<https://codebeautify.org/jsonviewer>

Untitled

In the Tree Viewer on the right, click the arrow next to ‘Object’ to collapse the data.

Untitled