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)