Skip to main content

Command Palette

Search for a command to run...

REST API Design Made Simple with Express.js

Understanding REST APIs, HTTP methods, and clean route design in Express.js

Published
•6 min read
REST API Design Made Simple with Express.js
G
I enjoy blending technology with business to build solutions that create real impact. I’m fascinated by how technology empowers people, businesses, and startups. I believe thoughtful use of technology quietly improves lives, and that belief fuels everything I build and explore 💻.

If you’ve started backend development recently, chances are you’ve already heard the term REST API being used everywhere. Whether you’re building authentication systems, social media platforms, e-commerce applications, or dashboards, REST APIs become one of the core parts of backend communication. Initially, terms like routes, resources, HTTP methods, status codes, and endpoints may feel slightly confusing because many concepts appear together at once. But honestly, the core idea behind REST APIs is actually very simple once you understand how client-server communication works.
At a very basic level, APIs allow the frontend and backend to communicate with each other. Whenever a frontend application needs data, it sends a request to the backend server, and the backend responds with the required information. REST APIs simply provide a structured and organized way of handling this communication.

In this blog, we’ll understand what REST APIs actually are, what resources mean in REST architecture, how HTTP methods work, what status codes represent, and how to design cleaner routes in Express.js using proper REST principles.

What REST API Actually Means

REST stands for Representational State Transfer. The name sounds complicated initially, but in practice REST APIs are mainly about designing backend routes in a clean and predictable way.
A REST API allows clients and servers to communicate using HTTP requests. The client sends a request, the server processes it, and then the server sends back a response.

For example:

GET /users

This request may ask the server to return all users.

Similarly:

POST /users

This request may ask the server to create a new user.
The main idea behind REST is keeping routes structured around resources instead of random route naming.

Understanding Resources in REST APIs

Resources are one of the most important concepts in REST architecture.
A resource simply means the main data entity your API is working with.
Examples:

  • users

  • products

  • posts

  • orders

  • comments

Suppose you are building a social media backend. In that case, users and posts may become resources.

Instead of creating routes like:

/getAllUsers

REST principles usually prefer cleaner resource-based routes like:

/users

This makes APIs easier to understand and maintain later.

Understanding HTTP Methods

REST APIs heavily use HTTP methods for defining actions. Instead of creating separate route names for every operation, REST combines routes with HTTP methods to describe behavior.
The four most common methods are:

  • GET

  • POST

  • PUT

  • DELETE

These methods directly map to CRUD operations.

GET Request

GET is used for fetching data from the server.

Example:

GET /users

This may return all users.

Another example:

GET /users/101

This may return a specific user having ID 101.

In Express.js:

app.get("/users", (req, res) => {
  res.send("All users fetched");
});

GET requests are mainly used whenever the client wants to retrieve data.

POST Request

POST is used for creating new resources.

Example:

POST /users

This may create a new user in the database.
Express example:

app.post("/users", (req, res) => {
  res.send("User created");
});

POST requests usually carry data inside the request body.

PUT Request

PUT is used for updating existing resources.
Example:

PUT /users/101

This may update the user having ID 101.

Express example:

app.put("/users/:id", (req, res) => {
  res.send("User updated");
});

PUT requests are commonly used for editing or replacing existing data.

DELETE Request

DELETE is used for removing resources.

Example:

DELETE /users/101

This may delete the user having ID 101.

Express example:

app.delete("/users/:id", (req, res) => {
  res.send("User deleted");
});

This keeps route structures clean because the route remains the same while the HTTP method changes the operation.

Designing Routes Using REST Principles

One major beginner mistake is creating routes like:

/createUser
/deleteUser
/updateUser

While these technically work, REST APIs usually avoid action-based route naming.
Instead, REST focuses on resource-based routes:

/users
/users/:id

The HTTP method itself defines the action.
For example:

GET /users
POST /users
PUT /users/101
DELETE /users/101

This structure keeps APIs predictable and much easier to scale later.

Understanding Status Codes

Whenever the server responds to a request, it also sends a status code. Status codes help the client understand whether the request succeeded or failed.
Some very common status codes are:

  • 200 → Success

  • 201 → Resource created

  • 400 → Bad request

  • 404 → Resource not found

  • 500 → Internal server error

Express example:

app.get("/users", (req, res) => {
  res.status(200).send("Users fetched");
});

For resource creation:

app.post("/users", (req, res) => {
  res.status(201).send("User created");
});

Status codes make backend communication more meaningful because the frontend immediately understands what happened with the request.

Example REST API Structure for Users

A simple REST structure for a users resource may look like this:

GET /users
GET /users/:id
POST /users
PUT /users/:id
DELETE /users/:id

This single structure already covers fetching, creating, updating, and deleting users cleanly using REST conventions.

REST APIs became extremely popular because they are simple, predictable, scalable, and easy to understand. Frontend applications, mobile apps, and third-party services can all communicate with backend systems using the same standardized HTTP approach.
REST also keeps route structures clean because developers do not need to invent random naming patterns for every operation. Once someone understands REST conventions, most APIs start feeling naturally readable.

Final Thoughts

REST API design may initially look slightly confusing because terms like resources, routes, methods, and status codes appear together. But at its core, REST is mainly about organizing backend communication in a structured and predictable way.

Instead of building action-based routes, REST focuses on resources and HTTP methods. GET fetches data, POST creates data, PUT updates data, and DELETE removes data. Combined with proper status codes and cleaner route structures, REST APIs become much easier to build, maintain, and scale in real-world backend applications using Express.js.