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

Published: (December 7, 2025 at 05:29 PM EST)
4 min read
Source: Dev.to

Source: Dev.to

What Exactly Is an API?

API stands for Application Programming Interface. It acts as a bridge that allows two systems to communicate.
Think of a waiter at a restaurant: you (the user) place an order, 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.

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, a lightweight data format.

How API Requests Actually Work

When you click “Login” on Instagram, Snapchat, or any app, your browser compiles the data (usually as JSON) and sends it across the internet.

  1. DNS lookup – The Domain Name System translates the website’s name into an IP address so the request can locate the correct server.
  2. Middleware layers – Security checkpoints handle logging, authentication, and other preprocessing before the request reaches the backend controller.
  3. Controller – The brain of the operation; it processes business logic and runs queries against the database.
  4. Response – The backend gathers results into a structured JSON response, sends it back across the network, and the frontend unpacks the information to update the UI (e.g., log you in or show an error).

All of this round‑trip typically happens in a few milliseconds, making the interaction feel instantaneous.

What is a REST API

REST (Representational State Transfer) is the standard architecture used by most modern APIs. REST operates using endpoints such as:

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

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

What is an Endpoint

An endpoint is simply a URL + HTTP method that performs an action.

Examples

ActionExample Endpoint
Fetch all usersGET /api/users
Get a productGET /api/products/:id
Create accountPOST /api/register
LoginPOST /api/login

Types of Endpoint Inputs

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

Building Your First API Endpoint

Setup

npm init -y
npm install express

Create a file named server.js and add the following code:

// server.js
const express = require('express');
const app = express();
const PORT = 3000;

// Simple GET Endpoint
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 }
  });
});

What Are Middlewares? (Beginner‑Friendly)

Middleware = functions that run before your main logic.

app.use((req, res, next) => {
  console.log(`${req.method} ${req.url}`);
  next();
});

Common uses

  • Logging
  • Authentication
  • Data validation
  • Handling CORS

Middleware powers a large portion 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' });
  }
});

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

Testing APIs with Postman or Thunder Client

Example tests

GET request

  1. Select GET
  2. Enter http://localhost:3000/api/hello
  3. Click Send

POST request

  1. Select POST
  2. Enter the endpoint (e.g., http://localhost:3000/api/register)
  3. Go to Body → JSON and add data:
{
  "name": "Kelvin",
  "email": "kelvin@example.com"
}

Testing tools let you verify APIs without building a frontend.

To Round This Up

APIs are the invisible glue that connects frontends, databases, and third‑party services. By mastering the core lifecycle—understanding how requests trigger logic at endpoints, how middleware secures the pipeline, and how structured responses close the loop—you move from writing isolated functions to architecting robust, scalable systems. This foundational knowledge transforms the backend from a “black box” into a logical, manageable workflow where data flows predictably.

Back to Blog

Related posts

Read more »