DEV Community

Cover image for How APIs Really Work: A Beginner’s Guide to Building and Understanding Backend Endpoints
Kelvin Osagie
Kelvin Osagie

Posted on

How APIs Really Work: A Beginner’s Guide to Building and Understanding Backend Endpoints

APIs power almost every app we interact with daily, right from logging into your Instagram account to checking your bank balance or just booking a ride. But for beginners, APIs feel invisible. There’s no user interface, no animations, just data moving behind the scenes to attend to your commands.

In this guide, we’ll explore in depth how APIs actually work, what happens inside a backend server when a request comes in, and how to build your first real endpoint using Express.js. By the end of this article, you should understand APIs like a real backend developer.

What Exactly Is an API?

API stands for Application Programming Interface. Basically, it acts as a bridge that allows two systems to communicate. To give you a simple example, imagine a waiter walks up to you at a restaurant. You (the user) place an order, and the waiter (the API) takes that order to the kitchen (the server). Once the kitchen prepares the food, the waiter brings it back to you. And then in technical terms, the Frontend (e.g., React, Vue, HTML) makes a request, the API carries that request to the Backend to process the logic, and then the API returns a response. Almost all APIs communicate using JSON, which is a lightweight data format.

How API Requests Actually Work

When you do something like clicking "Login" on your Instagram or Snapchat, trying to get into your account, your browser compiles the data (usually as JSON) and sends it out, starting a high-speed journey across the internet. First, the Domain Name System (DNS) acts like a digital phonebook, translating the website’s name into an IP address specific to you so the request can locate the correct server. Upon arrival, the request doesn't go straight to the data; it first passes through "middleware" layers—security checkpoints that handle logging and verify your identity—before finally reaching the backend controller. This controller is basically the brain of the operation, processing the business logic and running queries against the database to fetch or verify the information you need.

Once the logic is processed and the database returns the necessary data, the backend then gathers the results into a structured JSON response. This package is sent back across the network to your frontend, which unpacks the information and updates your screen, like logging you in or showing an error message if it doesn't go through. Remarkably, this entire round-trip process—involving network travel, security checks, code execution, and database lookups—is optimized to happen in just a matter of milliseconds, making the interaction feel immediate to the user.

What is a REST API

REST means Representational State Transfer. It’s the standard architecture used by most modern APIs. REST operates using endpoints like:

GET /api/users
POST /api/login
GET /api/products/:id
DELETE /api/posts/12

REST APIs use:
HTTP Methods
GET – Fetch data
POST – Send data
PUT – Update data
DELETE – Remove data
Common Status Codes
200 – OK
201 – Created
400 – Bad Request
404 – Not Found
500 – Server Error
Enter fullscreen mode Exit fullscreen mode

What is an Endpoint

An endpoint is simply a URL + HTTP method that performs an action.
Examples:
Action
Example Endpoint
Fetch all users

GET /api/users
Get a product
GET /api/products/:id
Create account
POST /api/register
Login
POST /api/login
Enter fullscreen mode Exit fullscreen mode

Types of endpoint inputs

Route params: /users/:id
Query params: /search?keyword=api
Body data: { "email": "test@gmail.com" }
Enter fullscreen mode Exit fullscreen mode

Building Your First API Endpoint

Let’s create a simple backend server.
Setup

npm init -y
npm install express

Create a file: server.js
Simple GET Endpoint
const express = require('express');
const app = express();
const PORT = 3000;

app.get('/api/hello', (req, res) => {
  res.json({ message: 'Hello, world!' });
});

app.listen(PORT, () => console.log(`Server running on port ${PORT}`));

How it works:
app.get() → listens for GET requests
/api/hello → endpoint URL
req → incoming request (data coming in)
res → server response (data going out)

POST Endpoint (Sending Data)
app.use(express.json()); // To read JSON body

app.post('/api/register', (req, res) => {
  const { name, email } = req.body;

  res.status(201).json({
    message: 'User created successfully',
    data: { name, email }
  });
});
Enter fullscreen mode Exit fullscreen mode

What Are Middlewares? (Beginner-Friendly)

Middleware = functions that run before your main logic.
Example:
app.use((req, res, next) => {
console.log(${req.method} ${req.url});
next();
});

Uses:
Logging
Authentication
Validating data
Handling CORS
Middleware powers 60% of a backend system.

How APIs Talk to Databases

Endpoint → Controller → Database → Response
Simplified example:
app.get('/api/user/:id', async (req, res) => {
  try {
    const user = await User.findById(req.params.id);
    res.json(user);
  } catch (error) {
    res.status(500).json({ message: 'Server error' });
  }
});
Enter fullscreen mode Exit fullscreen mode

Even though you’re not using a database yet, this pattern appears in every backend.

Testing APIs with Postman or Thunder Client

To test:

GET request
Select GET
Enter: http://localhost:3000/api/hello
Click Send
POST request
Select POST
Enter endpoint
Go to Body → JSON
Add data:
{
  "name": "Kelvin",
  "email": "kelvin@example.com"
}
Enter fullscreen mode Exit fullscreen mode

Testing tools let you test APIs without building a frontend.

To Round This Up

APIs are much more than just code; they are the fundamental backbone of modern backend development, acting as the invisible glue that connects frontends, databases, and third-party services. By mastering the core lifecycle—understanding how specific requests trigger logic at endpoints, how middleware secures the pipeline, and how structured responses close the loop—you move from simply writing functions to architecting robust, scalable systems. This foundational knowledge transforms the backend from a confusing "black box" into a logical, manageable workflow where data flows predictably.

Top comments (0)