using api's to unlock data everywhere
understanding what API's are and how they work is a key skill to add to your toolkit
Today we’re talking about one of the most common ways for data scientists to access data: an API, also known as an application programming interface. Understanding what an API is and how to use can open up endless avenues to interface with real-time production level data on the everyday.
what’s an api?
An Application Programming Interface is the middle man between two computer systems that allows the systems to communicate. The hand-wavey definition is best brought to life through an example.
I’m online shopping, looking at some new workout clothes. After finding what I’d like to get, I head to checkout and pay. Remember when their used to be on payment option? Well, now you probably see a screen like this:
Current state: the user is on their shopping checkout page and looking to make a payment via one of these methods.
Each of these methods can’t possibly process my payment in the same way. By clicking on one of these buttons, I’m deciding which method I will choose to process my payment data.
Let’s pick Apple Pay. I need to give them some data (such as the price of the items in my cart, the tax I’ll be charged, and my credit card information) in exchange for them sending me back data that confirms the payment has been processed.
The website I’m shopping on needs to send data to Apple Pay so they can do their service and send the website data back that the payment has been processed. Apple Pay doesn’t care about what I’m shopping for on the website, and the website doesn’t care how Apple Pay processes the payment. Both systems just need to be able to talk to each other, receiving and outputting the relevant information.
How does this communication happen between the website and Apple Pay?
Enter the API.
Some terms to know:
Endpoint: “A digital location where an API receives requests about a specific resource on its server” as defined by HubSpot
REST API: one of the more common types of API’s that conforms to the REST style of architecture — simply stated, these API’s have a common form they follow if you’d like to use them
GET, PUT, POST, and DELETE are different commands you can use to interact with data that is behind a REST API
The website embeds a bit of code into their front-end that allows the user to interact with a powerful payment processing system (Apple Pay) without actually needed to send their data manually or know the details of payment processing.
There’s two pieces of the puzzle here - a “client” and a “server”. The client will request data from the server, who will then send a response. The API is the interface that allows for this data transfer to happen. It’s as simple as that. This easy transfer of data is what enables powerful APIs to work quickly and reliably.
An example API request:
If you’re looking to Get Tracks from Spotify’s Web API, you could use this HTTP code snippet
GET /v1/tracks/id HTTP/1.1
Content-Type: application/json
Authorization:
Host: api.spotify.com
why use api’s?
API’s have been a major game changer in the ability to integrate software at scale. Instead of a company having to manage relationships with external apps that want to use their platform, they can provide an easy-to-embed API endpoint that scales their product with little effort on their end. API’s also allow for access to real-time data for developers and data scientists to interact with in their projects. Rather than exporting troublesome Excel spreadsheets or managing customized querying of databases, API’s give users access to lots of data that they can manipulate and query on their own.
Think about Resy, the restaurant booking platform. Their company would have had a lot less success had it not been able to be embed on any restaurant’s website. If you had to navigate away from a restaurant’s website to make a reservation, the impediment in the user flow would lead to lower rates of adoption and most likely less users overall.
api’s can lead to big wins for software
Twitter’s API has been in the news lately, since their development team recently removing free use of their API which allowed users to tweet from third-party platforms and enable developers to create cool products based off of Twitter and its data.
Twitter’s API has been huge for innovation at the social media company. Developers have created platforms that have grown Twitter’s user base for free essentially, with no payment back from Twitter as a “thank you”. In the days before photos were allowed on the app, users had to use a third-party platform TwitPic built off the Twitter API to post a picture of their epic lunch. Third party applications are to thank for popularizing the word “tweet”, among several other contributions these platforms have made mainstream.
By allowing for users to interact with an application in an easy way, you can grow at scale and inspire developers outside of your team to innovate further.
api’s for you to try
OpenWeather allows you to integrate real-time weather data into your application.
Yelp lets you see reviews and details of your favorite restaurants, bars, and more.
Nasa has a trove of API’s if you have an app that’s in need of an out-of-this-world data layer.
Spotify allows you to search for music, get recommendations, and get detailed data on the beats, rhythm, and composition of a song.
that’s a wrap
And now you’ve got an understanding of a new way to access data. APIs are a crucial part of data access in industry and research, and understanding them are a valuable skill to add to your data science toolkit.