Programming the Web with APIs – Tim Ribaric and John Fink – Why are APIs important?

Programming the Web with APIs – Tim Ribaric and John Fink – Why are APIs important?

0 0


Slides for OLA 2014 API talk

On Github jbfink / OLA2014-API

Programming the Web with APIs

Tim Ribaric and John Fink


Who are we?

Who are you?

Why are APIs important?

Why APIs matter to the web

  • They are the lingua franca of the Internet
  • Ensure that communication can happen between different sites and different versions
  • Provide a consistent reliable way for information to be delivered
  • They abstract some of the complications of the underlying technologies

Why in the Library?

  • Provides an unencumbered interchange of data
  • Perfect example, a union catalogue based on MARC
  • ILL just wouldn't be possible without an underlying API
  • Copy Cataloguing would be difficult as well

Where it could have helped

  • Imagine if every database vendor provided an API?
  • You could make your own Google Scholar
  • Google Scholar exists because the web is more or less recognizable as an API
  • Without ubiquity of web we'd just have: AOL Online, Prodigy, Compuserve, etc
  • Your Gmail message wouldn't get to your Yahoo Grandma

Demonstration of API

Application Programming Interface

Person as program, computer as "API". Let's take a search, for example. This is just a fancy way of saying "how to make one thing talk to another thing.

You as a client, browser as API

  • "Hey, I wonder who directed Jason X?"
  • "Let's go to IMDB and find out."
  • "here's my browser..." tappity tappity type...
This aside has a swear word in it. "Fuck", I say.

This is good and this is bad

  • This is great for *us*...
  • ...but not so great for *machines*
  • Machines are dumb, so we make it simple. They want...
  "Title": "Jason X",
  "Year": "2001",
  "Rated": "R",
  "Released": "26 Apr 2002",
  "Runtime": "91 min",
  "Genre": "Horror, Sci-Fi, Thriller",
  "Director": "James Isaac",
  "Writer": "Victor Miller (characters), Todd Farmer",
  "Actors": "Kane Hodder, Jeff Geddis, Lexa Doig, David Cronenberg",
  "Plot": "Jason Voorhees returns with a new look, a new machete, and his same murderous attitude as he is awakened on a spaceship in the 25th century.",
  "Language": "English",
  "Country": "USA",
  "Awards": "1 nomination.",
  "Poster": "",
  "Metascore": "25",
  "imdbRating": "4.3",
  "imdbVotes": "31,145",
  "imdbID": "tt0211443",
  "Type": "movie",
  "Response": "True"

If we get data like this we can pull out information in a *programmatic* way...

curl --silent "" | jq '.Director'
"James Isaac"

It's alive!

An API from Library Land.

Digital Public Library of America

Request an API key, then you are good to go

curl -v -XPOST

Oodles of ways to interact

keyword search for Frankenstein

Oodles of ways to interact

items from before 1923


URL of the actual image file

[{"name":"Motion pictures"},
{"name":"Boris Karloff"},
{"name":"Performing Arts"},
{"name":"Actors and actresses"},
{"name":"Freulich, Roman"},
{"name":"Karloff, Boris"},

Subjects tagged in the record

Time to make Apps!

API to the rescue

One API, three uses

  • When are you open until?
  • ...On Halloween
  • (I'm trying my best here people)
  • Needed some easy way to display what hours we were open
  • Wanted to make it easy to re-use this information
  • Made an in-house API that spits out hours in JSON

Can open this in any browser
	"location_name":"Help Desk",
	"schedule_name":"Fall Term",

What happens when there is no API?

Screen scraping happens

Screen Scraping

  • True nightmare on Elm Street
  • Systematically extracting text from a webpage
  • A very fickle business at best
  • Tools exist that help with the process

Beautiful Soup

  • Software package that downloads a webpage
  • It then organizes the HTML by tag
  • You can then traverse the data, sorta

Legality of Scraping?

Example of scraping

Finding the length of a movie using IMDB

Ah there it is!

Ctrl + U to view source, then try to search for it

Not fun

Followup for the curious


Tim Ribaric


John Fink