Web APIs

Server-side Web Application Program Interfaces (APIs) are defined methods designed to make interaction with a server easier. Think of them as recipes or contracts, where if you provide the expected input you will receive an expected output. Web APIs provide an abstract way to interact with a server from the outside using a web protocol (http) to request or submit data.

power strip and plugs
For Example...

Think about the outlets in your house. Any device with the standard plug can be connected to the socket and receives the standardized amount of power. You do not need to know anything about the power generation or electrical grid that delivers it to your house (other than paying the bill). Likewise, the utility company doesn’t need to know what you are plugging in, it just delivers the expected voltage. This makes the interaction considerably simpler–you do not need to rig up custom wiring and voltage regulators for every device.

Many cultural institutions provide APIs allowing users to access information about their collections via simple HTTP requests. These sources enable new queries and aggregations of text that were previously impossible, cutting across boundaries of repositories and collections to support large scale analysis of both content and metadata.

GET Demo

The simplest forms of APIs use the HTTP GET method, essentially utilizing URL patterns to request information from a server. With GET requests, your query is encoded in the URL string, thus limited in length (2048 ASCII characters), complexity, and security.

We can test using these APIs simply by constructing the URL following the recipe, then pasting it into a web browser. However, combining these methods with a tool such as OpenRefine or a scripting language such as Python can make them very powerful.

Uniform Resource Locators

Understanding the URLs in your browser address bar is the first step to using this type of API. So let’s dissect a URL:

protocol :// domain . top-level domain (optional port :80) / path and filename ? query with parameters # fragment or anchor

IIIF

International Image Interoperability Framework (IIIF) is an effort to standardize methods to access images and annotations from repositories. The API standard was created by a collaborative community so that software developers can create compliant viewers and image servers, enabling better user and developer experiences across many platforms.

IIIF URI syntax looks like:

{scheme}://{server}{/prefix}/{identifier}/{region}/{size}/{rotation}/{quality}.{format}

Each parameter has standard options or syntax, gradually building up the exact specifications of the image you want.

Using the IIIF Image API, let’s create an image download link for objects in our potlatch-historical-collection.csv demo project, which are hosted in the University of Idaho Library’s PHS collection on the CONTENTdm platform.

Parts of the recipe:

Steps:

DBpedia API

APIs also offer opportunities to enrich your data or connect with other sources. DBpedia Spotlight is a web service to annotate text with linked open data entries from DBpedia. For example, let’s say we want to extract entities from this text and link them to DBpedia: “Moscow, Idaho is located in the Palouse near Pullman, Washington.” First, try pasting the GET URL into your browser to see how it works:

https://api.dbpedia-spotlight.org/en/annotate?text=Moscow, Idaho is located in the Palouse near Pullman, Washington.

The API has returned an HTML page, because the request came from a browser it assumes we want it in that form. However, we may need another machine-readable format. The API will return application/json, text/xml, or application/xhtml+xml if we pass it as the Accept header in our request.

Parts of the recipe:

Steps: