What is an API? A Comprehensive Beginner’s Guide And Mini Tutorial

So you want to build a website for cocktail recipes. You expect your users to search by drink name or ingredient, and get a few recipes based on what they pick? 

How do you build this without writing up hundreds of cocktail recipes, and structuring the data in a database, and create all the logic to access the data?

The answer is to use an API. Since someone has already created the data for you to use.

We will come back to this example to see how easy this project can be by using an API and Postman to make API requests.

API: An Introduction for Beginners

In this article, we’ll be introducing you to the world of APIs. We’ll talk about what they are, why they’re useful, and how to use them. By the end of this article, you should have a good understanding of what APIs are and be able to understand why you would use them in your own projects.

What is an api?.

What is an API?

API stands for “Application Programming Interface”. An API is a set of rules that govern how two pieces of software interact with each other. When you use an API, you are essentially telling one piece of software how to communicate with another piece of software.

For example, when you use Google Maps on your phone, you are using the Google Maps API. The Google Maps API tells your phone how to communicate with the Google Maps servers in order to fetch the map data that you see on your screen.

There are also internal APIs that you use when building an iOS app. For example, Apple offers a weather API which lets you display the user’s local weather in your app.

Why Use APIs?

APIs are a great way to add functionality to your project without having to write all the code and gather all the data yourself. Software developers can access only the parts of the remote software they need for their project without having to worry about all the underlying complexity.

In general, APIs make it easy for developers to add new features to their project without having to start from scratch. So if you’re looking to add some extra functionality to your project, an API is definitely worth considering.

History of APIs

The first APIs were created in the early days of the internet as a way to access information from web servers. These early APIs were simple and limited, but they laid the foundation for the more complex APIs that we use today.

As the internet evolved, so did APIs. Today, APIs are used by developers to access data and functionality from all sorts of online services. For example, the Twitter API lets developers build apps that access Twitter data like number of followers. And the Instagram Reels API lets developers build apps that let their users create IG Reel videos on a Instagram. Those are just some of the social media APIs.

APIs have become an essential part of the internet, and they will continue to play a vital role in the years to come.

How do APIs work?

An API is a set of rules that govern how software components interact with each other. When you use an API, you are essentially using a set of pre-written code that somebody else has written. This code handles all of the low-level details so that you can focus on the higher-level functionality of your own code.

APIs are a very important part of software development, as they allow developers to reuse code and components that have already been created. This can save a lot of time and effort, as well as provide a higher level of quality and consistency.

Understanding APIs Without Writing Code

If you are a software developer, then you are probably already familiar with APIs. However, if you do not code, then it’s often useful to see a real life API example to make it more tangible and make sure you understand. We will use a REST API, which is the most common form of API today.

A great tool that you can use to test and understand APIs is Postman. Go to postman.com and set up a free account and download the app or try the web version. Let’s go through a simple example together.

Connect To Your First API

Check out thecocktaildb.com. You can type in a drink name and get the ingredients and instructions on how to make the cocktail. This is a great database that is accessible via an API, sometimes called a web API.

When you click the API page, you can see examples of URLs to different API endpoints. The first URL example shows you how to search for a cocktail by name.

www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita

The first part of the URL until the “php” is the API endpoint. This is same regardless which cocktail you want to search for. Every time you want to search for a cocktail, this is the endpoint you use.

The second part of the URL is “s=margarita”. The letter “s” denotes that you want to do a search and the value after the “s” is the name of the drink. In this example, the drink you are searching for is a “margarita”. This pair of query parameter values (“s” and “margarita”) is called a key-value pair and are listed after the “?”.

Let’s now open Postman. First create a new workspace, and then a new collection in that workspace. I called my workspace “Free API” and my collection “Free APIs”. You can give them any name you want.

You will see a screen similar to this. There is a blue link for “Add a request”. Click that and let’s connect to a real API.

Postman social media API call
Postman

Copy and paste the URL from cocktaildb in the field “Enter request URL” and Postman will recognize this as an API call.

Entering a postman API call
Enter the URL

You can see in the Params section that Postman added a key for “s” and a value “margarita” for this key. You can type over the value and the link above will update.

Let’s change the value to “martini” and as we type we can see that Postman is also updating the URL.

Sending the postman API call.
Change the value to martini

Now press the “Send” button. After a second, you will see a bunch of data populate the lower panel. This date is structured as JSON, which is easy for us to read. You can see the instructions, ingredients, and more information that you can display in your new website.

Congratulations! You just made your own API call and got data from a remote server. You can change the drink name and make more calls to get the data that you need.

Results of a Postman api call

Conclusion

In this article you learned some of the theory behind APIs as well as made your own API calls using Postman to see how to get data from a remote server.

As you continue your journey, it’s always helpful to search out APIs that can make your job easier or improve your time to market for your product.