A Simple API Summary

Iftekher Mamun
3 min readMay 19, 2019

--

Source

Have anyone ever said the following to you?

Oh, just call an API request to get the json file

Me too, and at first, it sounded gibberish. But as it is a programmer’s job to be as efficient as possible, we often shorthand a lot of technical term and expect our peers to know what we are saying- plus we also have google to look up anytime we get confused.

API stands for Application Program Interface and not Automated Programming Interface as I once thought when I heard API first. It is a great way to quickly receive small amounts of information live from the internet (a specific website or data server) without actually visiting the website.

Normally, when you are visiting a website in your browser, your browser is asking the website server for access to the request website. If URL matches, then the request is accepted and the website loads in a new page. You can notice this if you visit a website on a day you have particularly slow internet (and a very image/media heavy website) and looking at the lower left of your browser where all steps are quickly written out. API works in similar fashion, but instead of asking to load the website, it request the data that is within the website. Using BeautifulSoup4 request method for URL and adding an endpoint of what you wish to search for plus .json() allows you to receive the data contained within the website. But be aware that it will only return the specific endpoint you asked for and if it doesn’t not match, you will receive one of several errors.

A great example used by Petr Gazarov on his article What is an API is the Google Calendar. When you RSVP to an event that is linked with your Google Account- for example meetup groups- they automatically update your (at least mine does) calendar with the event without having to leave the meetup app. If I receive an invitation to an event in my gmail, that is also automatically updated within my calendar depending on my response; but I do not have to open and manually input anything in my calendar- unless I want to change something. That is because of APIs.

A more robust version of API is RESTful API. As described in Search Microservice, RESTful API

is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data

REST is acronym for REpresentational State Transfer. In its most simple term, REST takes in a request and breaks it down to smaller modular nodes and search for information. They use one of the four commands above to finish the transaction. Get is similar to request.get as it will display the information you are asking for. Put will change the data you are looking it, Post will create a new data/ resource and Delete will delete the target transaction. Since REST is stateless, it is helpful in cloud based operation systems and can be used to scale largely, quickly. However, creating a RESTful system from scratch is rather difficult so most developers rely on already developed third party sources.

There are six core principles for RESTful API to work. I will list those six but their description can be found at the REST API Tutorial:

Client–server

Stateless

Cacheable

Uniform interface

Layered system

Code on demand (optional)

For a great example on API live coding, I recommend the Data Science Tutorial: Introduction to APIs in Python. It is a great resource that breaks down how to request specific endpoints and parameters using python.

--

--