Understanding API Calls with Real Example

A Beginner-Friendly Guide to APIs

You’ve probably heard of the term API if you’ve been exploring programming, web development, or app creation. But what exactly is an API? More importantly, how do API calls work, and why are they essential in modern software development?

Understanding API Calls

This blog explains what API calls are, how they work, and how to use them with real-life examples. Whether you're a student, beginner coder, or tech enthusiast, you’ll walk away with a clear understanding of how to use APIs practically.

What Is an API?

API stands for Application Programming Interface. It’s a set of rules and protocols that allows different software applications to communicate with each other.

In simple terms:

An API acts like a messenger between two systems that need to talk to each other.

Real-World Analogy

Imagine you’re at a restaurant:

  • You (user) sit at a table and decide what to eat.
     
  • The waiter (API) takes your order and goes to the kitchen (server).
     
  • The kitchen prepares the food and gives it to the waiter.
     
  • The waiter delivers it to you.
     

In this analogy:

  • You = frontend app
     
  • Waiter = API
     
  • Kitchen = server or backend

What Is an API Call?

An API call is the process of a client (like your application or browser) sending a request to an API to fetch or send data.

This request follows a structure and goes to a particular endpoint — a URL on the web that the server listens to. The server processes the request and returns a response, usually in JSON format.

Basic Components of an API Call

Here’s what an API call typically consists of:

ComponentDescription
EndpointThe URL that the request is sent to
MethodHTTP method (GET, POST, PUT, DELETE, etc.)
HeadersExtra information like authentication tokens
BodyData sent with POST/PUT requests
ResponseWhat the server sends back (usually in JSON)

Types of HTTP Methods

MethodDescriptionExample Usage
GETRetrieve data from the serverGet user details
POSTSend new data to the serverAdd a new product
PUTUpdate existing dataUpdate user profile
DELETERemove data from the serverDelete a post

Real-Life Example: Weather API

Let’s say you’re building a weather app that shows current weather for any city.

You can use a free API like OpenWeatherMap to get this data.

Step 1: Get Your API Key

  • Sign up at openweathermap.org
     
  • You’ll receive an API key after registration
     

Step 2: Construct the API Call

Endpoint:

bash

CopyEdit

Copy Code

https://api.openweathermap.org/data/2.5/weather

Full API Call with Parameters:

bash

CopyEdit

Copy Code

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

Here:

  • q=London is the city
     
  • appid=YOUR_API_KEY is your unique token
     

Step 3: Send the API Call (Using JavaScript)

javascript

CopyEdit

Copy Code

fetch('https://api.openweathermap.org/data/2.5/weather?q=London&appid=YOUR_API_KEY')

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

  .then(data => {

    console.log('Weather:', data.weather[0].description);

    console.log('Temperature:', data.main.temp);

  })

  .catch(error => console.log('Error:', error));

How API Responses Look (JSON)

Here’s a sample response:

json

CopyEdit

Copy Code

{

  "weather": [

    {

      "description": "clear sky",

      "icon": "01d"

    }

  ],

  "main": {

    "temp": 298.15,

    "humidity": 60

  },

  "name": "London"

}

You can extract values like:

  • data.weather[0].description → “clear sky”
     
  • data.main.temp → 298.15K

Where Are APIs Used in Real Life?

1. Social Media – Facebook, Twitter APIs for posting and reading content.

2. Payments – Razorpay, Stripe, Paytm APIs for secure payments.

3. Maps & Location – Google Maps API for real-time directions.

4. E-commerce – Amazon APIs for listing products, tracking shipments.

5. Finance – Stock market APIs for live data.

Popular Public APIs for Practice

API NameUse CaseURL
OpenWeatherMapWeather forecastsopenweathermap.org
CoinGeckoCryptocurrency datacoingecko.com
Cat FactsFun random cat factscatfact.ninja
SpaceX APISpace launch dataapi.spacexdata.com
JokeAPIProgramming jokesjokeapi.dev

How to Make API Calls in Python

python

CopyEdit

import requests

Copy Code

url = "https://api.coindesk.com/v1/bpi/currentprice.json"

response = requests.get(url)

data = response.json()

print("Bitcoin Price in USD:", data['bpi']['USD']['rate'])

This fetches the current Bitcoin price in USD from the CoinDesk API.

Tools to Test APIs

Before integrating APIs into your code, it's helpful to test them using tools like:

1. Postman – Most popular GUI tool for testing APIs.

2. Insomnia – Lightweight alternative to Postman.

3. cURL – Command-line tool for sending API requests.

Example using cURL:

bash

CopyEdit

Copy Code

curl “https://api.openweathermap.org/data/2.5/weather?q=Delhi&appid=YOUR_API_KEY”

Authentication in APIs

Many APIs require authentication via:

  • API Key
     
  • OAuth 2.0
     
  • Bearer Tokens
     

You pass the token in the request header:

http

CopyEdit

Copy Code

GET /users HTTP/1.1

Host: api.example.com

Authorization: Bearer YOUR_ACCESS_TOKEN

Best Practices When Using APIs

Best PracticeWhy It’s Important
Keep your API keys secretAvoid data leaks or misuse
Handle errors gracefullyCatch and display user-friendly messages
Use pagination for large dataPrevent performance bottlenecks
Respect API rate limitsPrevent getting blocked
Read the documentationUnderstand required parameters and structure

Common Error Codes in API Responses

CodeMeaningDescription
200OKRequest was successful
400Bad RequestClient sent incorrect data
401UnauthorizedInvalid or missing credentials
404Not FoundEndpoint or data doesn’t exist
500Internal Server ErrorSomething went wrong on the server

How to Learn More About APIs

1. Read API documentation thoroughly.

2. Watch tutorials that demonstrate step-by-step calls.

3. Build small projects (weather app, currency converter).

4. Practice on public APIs before using paid ones.

Simple Project Idea Using APIs

Project: Crypto Price Tracker

  • Use the CoinGecko API.
     
  • Let users select a cryptocurrency (e.g., Bitcoin, Ethereum).
     
  • Display current price in INR and USD.
     
  • Refresh price every 30 seconds.
     

This helps you practice:

  • Fetching API data
     
  • Displaying live data on the web
     
  • Using setInterval in JavaScript

Final Thoughts

APIs are everywhere — from booking rides to ordering food to sending money online. Understanding how API calls work gives you the power to connect your applications with real-world services.

If you're learning development in 2025, knowing how to read API docs, send requests, and handle responses is as important as writing code itself.

Want to Learn API Integration with Real Projects?

Check out Uncodemy’s Web Development & Backend Courses, where you’ll:

  • Learn how to build apps using real APIs
     
  • Work on live projects like weather apps and payment systems
     
  • Get step-by-step training on REST API creation and usage
     

📍 Visit uncodemy.com to explore full-stack development courses tailored for beginners and professionals alike.

Placed Students

Our Clients

Partners

...

Uncodemy Learning Platform

Uncodemy Free Premium Features

Popular Courses