DEV Community

Cover image for What Really Happens When You Call an API
Md Mijanur Molla
Md Mijanur Molla

Posted on

What Really Happens When You Call an API

We use APIs every day.

  • Fetching user data
  • Sending login requests
  • Getting products from backend

But have you ever thought:

πŸ‘‰ What actually happens after you call an API?

Let’s break it down in simple, real-world steps πŸ‘‡


πŸ’‘ Step 1: You Trigger the Request

It starts when your code runs something like:

fetch("https://api.example.com/users")
Enter fullscreen mode Exit fullscreen mode

Or using Axios, Postman, anything.

πŸ‘‰ This creates an HTTP request


🌐 Step 2: DNS Lookup (Finding the Server)

Before sending the request, your system asks:

πŸ‘‰ β€œWhere is api.example.com?”

So it contacts a DNS server.

DNS returns:

πŸ‘‰ The IP address of the server


πŸ“‘ Step 3: Request Travels Over the Internet

Now your request:

  • Goes through routers
  • Travels across networks
  • Reaches the server

πŸ‘‰ All this happens in milliseconds


πŸ” Step 4: Secure Connection (HTTPS)

If you’re using HTTPS:

  • SSL/TLS handshake happens
  • Connection gets encrypted

πŸ‘‰ Your data is now secure


βš™οΈ Step 5: Server Receives the Request

The server gets:

  • URL
  • Method (GET, POST, etc.)
  • Headers
  • Body (if any)

Now backend logic starts.


🧠 Step 6: Backend Processes It

Server does things like:

  • Validate request
  • Authenticate user
  • Run business logic
  • Fetch data from database

πŸ‘‰ This is the β€œbrain” of your app


πŸ—„οΈ Step 7: Database Interaction

If needed:

  • Server queries database
  • Gets data
  • Processes it

Example:

πŸ‘‰ β€œGet all users” β†’ DB returns rows


πŸ“¦ Step 8: Response is Created

Server prepares response:

  • JSON data
  • Status code (200, 404, 500)
  • Headers

πŸ‘‰ Example:

{
  "users": ["A", "B", "C"]
}
Enter fullscreen mode Exit fullscreen mode

πŸš€ Step 9: Response Travels Back

The response:

  • Goes back through internet
  • Reaches your app

πŸ‘‰ Again in milliseconds


πŸ’» Step 10: Your App Uses the Data

Finally:

  • UI updates
  • Data is displayed
  • User sees result

πŸ‘‰ That’s the moment you notice


πŸ”„ Simple Flow

πŸ‘‰ Request β†’ Internet β†’ Server β†’ Database β†’ Response β†’ UI


⚠️ Why Things Go Wrong Sometimes

If any step fails:

  • DNS issue
  • Network error
  • Server crash
  • Wrong API logic

πŸ‘‰ You get errors like 500, 404


🎯 Real Developer Insight

Calling an API is not just one function.

πŸ‘‰ It’s a full journey across systems

Understanding this helps you:

  • Debug faster
  • Design better systems
  • Think like a backend engineer

πŸš€ Final Thought

Next time you write:

fetch(...)
Enter fullscreen mode Exit fullscreen mode

Remember:

πŸ‘‰ You just triggered a multi-step process across the internet

And that’s the real beauty of software engineering πŸ’™

Top comments (0)