Coding Dojo

Male programmer working on laptop

What is an API?

As you embark on your coding journey, there are dozens of phrases you might not be familiar with. So, what is an an API
API stands for Application Programming Interface. It is a piece of code that lets two programs talk to each other. A way to pass information and data between two programs directly. Don’t worry, they’re not as complicated as they sound. An API is quite simple to use and a great way to get comfortable with some advance coding. Ultimately, you’re really only sending a small piece of code to a server to get a response.

What’s the point of an API?

There are many reasons to use an API, but ultimately it’s to quickly send useful information between two programs.
For example, imagine you’re developing a website. You want the website’s background to change based on the current weather.

How do you do it? You could set up a camera to look out the window, add some complicated machine learning to figure out whether it’s raining or not, and then change the background based on the result.
Alternatively, you could create a program that scrapes the local news and grabs the weather from the webpage.

Both of those options are rather inefficient. Instead, you can just go to OpenWeather and use their API to figure out the current weather in whatever location you please. Even better, you can do this all through one line of code by using an API.

This is a rather basic example, but the principle is the same: APIs take a complicated task and turn it into just a few lines of code. In the real world, you’re likely sending data from your application to a third party, who will process it on their end, and then you retrieve the answer. 

How APIs they work and what is an API Key?

An API can only send and retrieve data or functions that have been programmed into them. The creator of the API, will show which commands you’ll need to send to retrieve or send data to them. Often, you’ll also need an authentication code, more commonly known as an API key.

This is basically your login information and proves that the command you’re sending is coming from you. To interact with an API, it’s very similar to just typing in a web address. You’re just adding a little code to the URL, so it looks like this: api.acme.com/?get=bunny_season=a[authcode]

Once you send that, you’ll get a response. The format for the data you get back will depend on the API, but is often something like XML or JSON. And exactly how you make this request inside your code will depend on the programming language you’re using.

API Glossary

There are a few terms related to APIs you’ll likely come across while researching or working with them for the first time. Here’s what they mean:

What is an API Key?

An API key is more commonly known as an authentication code. It’s a unique string of of numbers that allows an API to identify a user or, more commonly, an application that is making a request. When applied to users, API keys are commonly used as an extra layer of security.

What is an API Call?

AN API call is simply the medium in which a request is sent or received. In order for programs to interact with each other, like in the weather example used above, your website homepage would be creating an API call to OpenWeather in order to receive the current temperature.

What is an API Gateway?

While an API call is the medium that manages requests, an API gateway is the aspect that organizes each requests so the end user is given the appropriate information. It effectively sits between a client and data, accepts all API calls, then returns them with the correct requested data.

What is an API Endpoint?

Perhaps the most self-explanatory term, an API endpoint is the point in which API connects with that actual software or user that is making the request or call.

What is an API Token?

Similar to an API key, an API tokens allows APIs to authenticate users. API tokens are less common than keys and are exclusive to users. They are smaller and faster to create than keys, thus making them more useful when authenticating a person as opposed to a program.

What can an API do?

There are typically only four actions you can take:

  • Get:. Ask for data from the server.
  • Post: Send data to the server and add it.
  • Put: Change data.
  • Delete: Delete data.

As you can see, while APIs might initially sound complicated, they’re really quite simple and make convoluted process easy. Using a combination of these actions, you can do pretty much anything you like with an API. It all depends on what the developer has set the API up to do.

How might you use an API?

Now that you know what an API is and what they do, You might use an API in three different ways:

An internal system

Let’s imagine you’re a global cinema company. You have a website with a booking system and a lot of cinemas, each with their own screens and seats. How do you know how many seats are available?

You might have a giant database that syncs everything, but that’s quite impractical. Instead, you could have an API with each cinema. Your website then pings the cinema, checks how many seats are available (and which ones they are) for the movie and then it sends back the response.

Your website can do all the heavy lifting of showing it to the user in a nice neat way. And because it’s a simple request, it doesn’t clog up the bandwidth for the cinema itself. That way, the user gets the same experience for every cinema. But also, you can easily just update the website if you have a design change.

Link with a partner

This time, let’s imagine we’re a data analytics company. You might have a tool that collects data from a museum. It takes data from the audio-tour device you give to people, records their path and then figures out what people enjoy. Great. But what if the museum wants to see that data in a better way?

You might not have the skills in-house to create the visualization. Instead, you might partner up with another company and use their software. An API is great for this. You can plug your two pieces of software into each other and have them work as a single unit. It’s not public data, so they use an authentication code to prove they can use the data.

Open up to the public

Lastly, you might just want to make your data public. OpenWeather, for example, wants anybody to be able to use its data. An open API lets you give this data to people, without them getting access to the raw database.

Learn to use APIs and more

If you’re interested in learning to program your own websites and use APIs to give them more functionality, you can check out at one of several Coding Dojo bootcamps, whether you want to learn on-site, online, part-time or full-time, there’s a bootcamp for you. You’ll get hands-on experience and learn to code three full stacks in a few months.