Friday, June 1, 2018

What is an API?

In short, APIs are like hotel desk receptionists – they can’t give you all the exact information, but they can give you data that the programmers decided to make usable by outside developers. In order to do something useful with that data, you have to ask the right questions.

Let’s start by defining the term API, which stands for “application programming interface”. The most important part of that elongation is actually the word “interface”. It’s important to note that an API provides a gateway for one program to talk to another. When a developer at a tech firm decides to publish an API for public use, they’ve made a portion of their code available to other developers. Using HTTP clients and URLS, other developers can then come along and use that code by requesting data from the open code, or the “end points”, of the API. Developers might want to use APIs when there exists a function or a dataset that they want to use without going through the trouble of writing that code or filing that data themselves. For example, rather than going through the trouble of finding the rating of every restaurant near me and filing that information into a database, I could just use the Yelp API to get that data for me.

So, an API is how programs talk to each other. Well, what all can they say? It turns out that APIs have just FOUR actions:
  1. GET: requests data
  2. PUT: adds to the existing entries
  3. DELETE: deletes existing entries
  4. POST: creates an entirely new entry

Though it seems limited (“Just FOUR?!”), these commands in combination can do just about anything you might need to do with information received from an API. Keep in mind: these actions remain the same across every API, but the syntax changes. Always check the API documentation to find out how to use that particular API. You can request data over a server by way of HTML or by JSON and XML, which are the main languages for accessing APIs.

While we’re talking about how an API talks, let’s also think about all the parts of an API. The architecture usually consists of 3 “people”: the user (developer making the request), the client (program that requests the server for data on behalf of the user), and the server (the program that completes or denies the request). Let’s consider an example. Assume that we want to make a directory (the server) outlining the personal profiles of everyone living in our neighborhood. I’ll collect their name, address, phone number, social security number, and birthday. However, I only want to publish their name and address and I want to keep their phone number, social security number, and birthday private. Thus, their name and address are the end points of my API, or my directory. Now, if I (the user) want a list of everyone in my neighbourhood that lives on Albion Rd., I just have to either 1. Make a URL request in a browser or 2. Create a program (the client) to request that information.

Now, you may be wondering how you can start using an API yourself. First, it is important to note that most if not all APIs require a key – this identifies and verifies you as a trusted developer. It’s fairly simple to get these keys; often times, verifying your email or Google account is enough. The best way to use APIs is to use an online HTTPS client, like Postman or apigee. These are great (and mostly free) tools that require very little actual coding. Download Postman here: https://www.getpostman.com/

In short, APIs are INCREDIBLE tools. For starters, they significantly lower the barrier of entry for smaller software firms by giving them access to data collected by large companies like Google, which have the resources to do so. But they also give independent developers like you and me an unimaginable amount of power.

Further Resources:
1. This youtube video teaches you how to use the Instagram and Google Maps APIs to pull up Instagram pictures posted near any given geographical coordinates. https://www.youtube.com/watch?v=7YcW25PHnAA
2. This is a link to the Twitter API documentation. I suggest reading this and trying a couple quick projects with this and Postman. Try posting a tweet to your account using the API! https://developer.twitter.com/en/docs/ads/general/guides/getting-started.html
3. Finally, this is a great Mulesoft article that discusses APIs again. https://www.mulesoft.com/resources/api/what-is-an-api

No comments:

Post a Comment