Importing HTTP Archive (HAR) Files to Create API Monitors

The HTTP Archive (HAR) format is a JSON file format that records the interactions of a web browser and web pages. HAR files can be used, for example, as a means for customers to record interactions with a web service, to record recurring problems and send them to a troubleshooting team.

The HAR format can also record the interactions that occur when a request is sent to an API. In this post, I’ll illustrate how to create an HAR file that queries the World Bank Countries API. Then, I’ll import the HAR file into my API Science account to create a new World Bank API monitor.

Creating the HAR File

Wikipedia notes that various software supports the creation of HAR files. In this demonstration, I’ll use Chromium Version 49.x running on Ubuntu Linux.

If your product is related to the Arctic Ocean, it might query the World Bank Countries API for information about the Russian Federation. The API endpoint for this request is: http://api.worldbank.org/countries/ru

Entering this URL into a browser produces a response web page like this:

world-bank-ru-web-view

Chromium includes a “Developer Tools” menu, that appears in different locations depending on the Chromium version and how you’ve configured your browser. In my case, clicking the three bars in the upper right corner of the browser window creates a pop-up menu that includes a “More tools” item. Clicking on this brings up a sub-menu that includes a “Developer tools” item. That item, in my case, includes the hint that the keyboard shortcut Ctrl+Shift+I will also bring me to the Developer tools panel.

Here’s what it looks like:

chromium-developer-tools-panel

I click the red circle at the upper left to initiate recording, and check the “Preserve log” item in the middle of the same row so that a log of all events will be created.

Next, in the browser’s URL entry field, I paste in the World Bank Countries API URL for the Russian Federation, and press “Enter” to initiate the request. Here is a typical result from my experiments:

chromium-world-bank-ru-recording

Now, we need to save the web activity as a HAR file. To do this, right-click the “ru” entry under the “Name” column at the lower right of the page. This will create a pop-up menu that has options including Copy All as HAR and Save. In the first case, you’ll have to create a text file, then you’ll paste in the stored request, the response results, and corollary data; in the second case, you’ll be prompted to enter a file name in which much-reduced information will be stored. Both HAR formats can be imported into your API Science account.

Using the HAR File to Create an API Science Monitor

Using the Chromium developer tools Copy All as HAR option, I created a HAR file named World_Bank_ru.har. Having stored that HAR file locally, I can now go to my API Science account and import the file to create a new API monitor.

Click “Import” in the top menu bar, scroll down to “HAR (HTTP Archive 1.2)”:

import-from-har-button

Clicking the “Import From HAR” button brings up the HAR Import page:

har_import_page

Since I’ve stored my HAR data as a local file, I click the “Import from File” tab, then click the “Browse” button to select the file. In the “File Upload” window that pops up, I navigate to my HAR file, select it, and click the “Open” button:

har-file-select1

Clicking the “Open” button brings this file into our API Science account, detects the API’s GET URI, and presents a page that enables us to create a monitor based on this:

har-import-uri-selection

Check the presented GET command and click the “Create Monitors” button to generate your new API monitor.

We’re brought to our API Science Dashboard, which now includes a new monitor named:

GET http://api.worldbank.org/countries/ru

Clicking this monitor’s name brings us to the new monitor’s summary page:

har-import-first-api-check

The first API check has been run, and this instance succeeded.

Conclusion

We’ve utilized the Chromium web browser to create an HTTP Archive (*.har) file based on navigating to a web page; then we’ve imported that HAR file to automatically create an API Science monitor that will regularly check the status of calls to that API.

Kevin Farnham