All posts

What is an API? A Beginner-Friendly Guide with Real Examples

What is an API? A Beginner-Friendly Guide with Real Examples


If you've spent even a few hours learning to code, someone has probably mentioned an API. But what actually is an API? And why do developers talk about it so much?


This guide breaks it all down in plain English — no jargon, no assumed knowledge. By the end, you'll know exactly what an API is, how it works, and how to start using one yourself.


--------------------------------------------------


What Does API Stand For?


API stands for Application Programming Interface.


Let's unpack that:


- Application — any software or program (a website, mobile app, or service)

- Programming — it's used in code

- Interface — a way for two things to interact


So at its core, an API is a way for two applications to talk to each other.


--------------------------------------------------


The Restaurant Analogy (The Best Way to Understand APIs)


Imagine you're at a restaurant.


- You are the user (or the frontend of an app)

- The kitchen is the server (or the backend/database)

- The waiter is the API


You don't walk into the kitchen and make your own food. You give your order to the waiter, the waiter takes it to the kitchen, and then brings your food back.


The API works the same way:


1. Your app sends a request (your order)

2. The API passes it to the backend server

3. The server processes the request and sends back a response (your food)


You never need to know how the kitchen works internally — you just interact with the waiter (the API).


--------------------------------------------------


A Real-World Example: Weather Apps


Have you ever wondered how a weather app on your phone knows the current temperature?


The app developers didn't build their own global weather tracking system. Instead, they use a Weather API — a service like OpenWeatherMap or Tomorrow.io.


Here's what happens behind the scenes:


1. You open the weather app

2. The app sends a request to the Weather API

3. The Weather API looks up the data and sends a response back

4. The app displays that data to you


The app and the weather service never share a codebase. The API is the bridge between them.


--------------------------------------------------


What is a REST API?


When developers say "API," they usually mean a REST API (or RESTful API).


REST stands for Representational State Transfer — but you don't need to memorize that.


HTTP Method | What It Does | Example

GET | Retrieve data | Fetch a list of blog posts

POST | Create new data | Submit a contact form

PUT/PATCH | Update existing data | Edit your profile

DELETE | Remove data | Delete a comment


These actions happen at a specific URL called an endpoint.


What is an API Endpoint?


An endpoint is simply a URL that your app sends requests to.


GET https://api.todaysdevs.com/posts

GET https://api.todaysdevs.com/posts/42

POST https://api.todaysdevs.com/posts

DELETE https://api.todaysdevs.com/posts/42


--------------------------------------------------


What Does an API Request and Response Look Like?


Here's a simple example using the free JSONPlaceholder test API.


Making an API Request in JavaScript


fetch('https://jsonplaceholder.typicode.com/posts/1')

.then(response => response.json())

.then(data => console.log(data));


The API Response (JSON)


{

"userId": 1,

"id": 1,

"title": "sunt aut facere repellat provident"

}


The API responded with JSON — JavaScript Object Notation.


--------------------------------------------------


What is an API Key?


Many APIs require an API key — a unique string of characters that identifies who is making requests.


https://api.openweathermap.org/data/2.5/weather?q=Nairobi&appid=YOUR_API_KEY


--------------------------------------------------


Public APIs You Can Try Right Now


- JSONPlaceholder — Fake data for testing

- Open-Meteo — Free weather data

- The Cat API — Random cat images

- REST Countries — Country information

- PokeAPI — Pokémon data


--------------------------------------------------


How to Call an API in JavaScript (Full Example)


async function getCountryInfo(countryName) {

const response = await fetch(

`https://restcountries.com/v3.1/name/${countryName}`

);


const data = await response.json();

const country = data[0];


console.log(country.name.common);

}


getCountryInfo('Kenya');


--------------------------------------------------


Why Are APIs So Important for Developers?


1. Reuse Instead of Rebuild


APIs let developers build on top of existing services instead of creating everything from scratch.


2. Separation of Concerns


Your frontend and backend can communicate independently through APIs.


3. Connecting Third-Party Services


APIs help apps integrate with email providers, payment systems, authentication, and more.


4. Building Products Faster


Developers can focus on unique features instead of rebuilding common infrastructure.


--------------------------------------------------


Quick Summary


API — A bridge that lets two apps communicate

REST API — An API style that uses HTTP methods and URLs

Endpoint — The URL you send a request to

JSON — A common format for API data


--------------------------------------------------


What to Learn Next


1. Practice fetching data with APIs

2. Learn async/await

3. Build a simple API project

4. Explore API documentation

5. Learn to build your own API


Found this helpful? Share it with another developer who's just getting started.

Check your own resume against any job

Free analysis — takes 30 seconds.

Analyse my resume free