REST API Design Made Simple with Express.js
Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
Search for a command to run...
Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
No comments yet. Be the first to comment.
Every day, millions of users upload photos, videos, stories, and reels to Instagram. From a user's perspective, the process appears simple: select media, apply filters, add a caption, and tap "Post."
Building Offline-First Messaging Apps: How Messages Work Without Internet Modern messaging applications have transformed the way people communicate. Whether it's chatting with friends, collaborating w
In this article we'll explore about the Expo Router and React Navigation and answer which one to use in 2026. If you build mobile apps using React Native, one thing becomes obvious very quickly: Navig

Modern mobile apps are no longer just a collection of screens connected together. Apps like Instagram, WhatsApp, Uber, and Netflix operate at massive scale with millions of users, real time systems, o
In this article we'll be exploring react.js and the things of react.js that makes it popular and stand out among other libraries ( no fight over library vs framework ). We'll go through: What problem

Shkaai
68 posts
When building backend applications, one of the most common patterns you will use is a REST API. It provides a clean and structured way for clients (frontend, mobile apps) to communicate with your server.
In this blog, you will understand REST concepts in a simple way and learn how to design APIs using Express.js.
REST stands for Representational State Transfer.
A REST API is a way of designing APIs where:
Everything is treated as a resource
Each resource is accessed using a URL
Standard HTTP methods are used to perform actions
/users
/products
/orders
Each of these represents a resource.
A resource is any data or entity in your application.
Examples:
User
Product
Order
Each resource:
Has a unique URL
Can be created, read, updated, or deleted
/users → collection of users
/users/101 → specific user
REST APIs use standard HTTP methods to define actions.
Used to fetch data from the server.
app.get('/users', (req, res) => {
res.send('Get all users');
});
Used to create a new resource.
app.post('/users', (req, res) => {
res.send('User created');
});
Used to update an existing resource.
app.put('/users/:id', (req, res) => {
res.send(`User ${req.params.id} updated`);
});
Used to delete a resource.
app.delete('/users/:id', (req, res) => {
res.send(`User ${req.params.id} deleted`);
});
Status codes tell the client what happened with the request.
200 OK → Request successful
201 Created → Resource created successfully
400 Bad Request → Invalid input
401 Unauthorized → Authentication required
404 Not Found → Resource not found
500 Internal Server Error → Server error
res.status(200).json({ message: 'Success' });
REST APIs follow a consistent structure.
GET /users → get all users
GET /users/:id → get one user
POST /users → create user
PUT /users/:id → update user
DELETE /users/:id → delete user
Use nouns, not verbs
Keep URLs clean and meaningful
Use HTTP methods for actions
Let’s build a simple example using Express.
import express from "express";
const app = express();
app.use(express.json());
let users = [];
// GET all users
app.get('/users', (req, res) => {
res.json(users);
});
// GET single user
app.get('/users/:id', (req, res) => {
const user = users.find(u => u.id == req.params.id);
if (!user) return res.status(404).send('User not found');
res.json(user);
});
// POST create user
app.post('/users', (req, res) => {
const user = { id: Date.now(), ...req.body };
users.push(user);
res.status(201).json(user);
});
// PUT update user
app.put('/users/:id', (req, res) => {
const index = users.findIndex(u => u.id == req.params.id);
if (index === -1) return res.status(404).send('User not found');
users[index] = { ...users[index], ...req.body };
res.json(users[index]);
});
// DELETE user
app.delete('/users/:id', (req, res) => {
users = users.filter(u => u.id != req.params.id);
res.send('User deleted');
});
app.listen(3000);
REST API is a structured way to design backend services
Everything is treated as a resource
HTTP methods define actions
Status codes indicate results
Routes should follow clean and consistent patterns
REST API design helps you build scalable and maintainable backend systems by following clear rules and standards. By treating data as resources and using HTTP methods correctly, your APIs become predictable and easy to use. Express.js makes implementing REST APIs simple with its clean routing system. Once you understand these principles, you can design APIs that are easy to expand, debug, and integrate with different clients such as web and mobile applications.