Skip to main content

Understanding REST APIs: The Foundation of Modern Web Communication

Updated 7 min readMarkdown

Every modern application — from social media apps to banking platforms — relies on APIs to communicate between frontend and backend systems.

When your React app fetches user data, submits a login form, or deletes a post, it is usually interacting with a REST API.

In this article, we’ll understand:

  • What REST API means

  • What resources are in REST architecture

  • HTTP methods:

    • GET

    • POST

    • PUT

    • DELETE

  • Status code basics

  • RESTful route design

  • Real examples using a users resource

  • The complete REST request-response lifecycle


What Is an API?

API stands for:

Application Programming Interface

An API allows two systems to communicate with each other.

Example:

Frontend App ↔ Backend Server

When a frontend needs data, it sends a request to the backend API.

The backend processes the request and returns a response.


Real-Life Analogy

Think of an API like a waiter in a restaurant.

Customer → Waiter → Kitchen
  • Customer = Client

  • Waiter = API

  • Kitchen = Server

The waiter takes requests and brings responses back.

Similarly:

Client → API → Server

What Does REST Mean?

REST stands for:

Representational State Transfer

REST is an architectural style used for designing APIs.

A REST API organizes data around:

Resources

instead of actions.


What Is a Resource in REST?

A resource is any piece of data managed by the server.

Examples:

  • users

  • products

  • posts

  • comments

  • orders

In REST APIs, resources are represented using URLs.

Example:

/users
/products
/posts

REST APIs Focus on Resources

Instead of routes like:

/getUsers
/createUser
/deleteUser

REST prefers:

/users

The action is determined by the HTTP method.


HTTP Methods in REST APIs

HTTP methods define what operation should happen on a resource.


1. GET → Fetch Data

Used to retrieve data from the server.

Example:

GET /users

Meaning:

“Give me all users.”


Get Single User

GET /users/1

Meaning:

“Give me the user with ID 1.”


2. POST → Create Data

Used to create new resources.

Example:

POST /users

Request body:

{
  "name": "Arnab",
  "email": "[email protected]"
}

Meaning:

“Create a new user.”


3. PUT → Update Data

Used to update existing resources.

Example:

PUT /users/1

Request body:

{
  "name": "Arnab Updated"
}

Meaning:

“Update user with ID 1.”


4. DELETE → Remove Data

Used to delete resources.

Example:

DELETE /users/1

Meaning:

“Delete user with ID 1.”


CRUD Operations vs HTTP Methods

CRUD Operation HTTP Method
Create POST
Read GET
Update PUT
Delete DELETE

RESTful Route Design

Good REST APIs use clean and predictable route naming.


Good REST Routes

GET    /users
GET    /users/1
POST   /users
PUT    /users/1
DELETE /users/1

Avoid Verb-Based Routes

Avoid:

/getUsers
/createUser
/updateUser
/deleteUser

Why?

Because the HTTP method already defines the action.

REST APIs focus on:

nouns (resources)

not verbs.


Understanding REST Request → Response Flow

Here’s the complete lifecycle.


Step 1: Client Sends Request

Example:

GET /users

The frontend asks the server for data.


Step 2: Server Processes Request

The backend:

  • validates request

  • fetches database data

  • performs business logic


Step 3: Server Sends Response

Example response:

[
  {
    "id": 1,
    "name": "Arnab"
  }
]

REST API Lifecycle Diagram

Client Request
      ↓
REST API Server
      ↓
Database / Logic
      ↓
JSON Response
      ↓
Client UI Updates

What Are Status Codes?

Status codes tell the client what happened.

Every API response includes a status code.


Common Status Codes

Status Code Meaning
200 Success
201 Resource Created
400 Bad Request
401 Unauthorized
404 Not Found
500 Internal Server Error

Example: Successful GET Request

HTTP/1.1 200 OK

Meaning:

Request succeeded.


Example: Resource Created

HTTP/1.1 201 Created

Meaning:

New resource was successfully created.


Example: Resource Not Found

HTTP/1.1 404 Not Found

Meaning:

Requested resource does not exist.


Why REST APIs Became Popular

REST APIs are popular because they are:

  • Simple

  • Predictable

  • Stateless

  • Easy to scale

  • Language-independent

Frontend and backend teams can work independently using API contracts.


Stateless Nature of REST

REST APIs are typically stateless.

This means:

Each request contains all information needed to process it.

The server does not remember previous requests automatically.


Example REST API for Users Resource

Here’s a complete example.


Fetch All Users

GET /users

Response:

[
  {
    "id": 1,
    "name": "John"
  }
]

Fetch Single User

GET /users/1

Create User

POST /users

Body:

{
  "name": "John"
}

Update User

PUT /users/1

Delete User

DELETE /users/1

REST Naming Best Practices

Use plural resource names

✅ Good:

/users
/products
/orders

❌ Avoid:

/getUser
/createProduct

Use Hierarchical Routes

Example:

/users/1/posts

Meaning:

Posts belonging to user 1.


REST APIs Usually Return JSON

Most modern REST APIs use JSON format.

Example:

{
  "id": 1,
  "name": "Arnab",
  "email": "[email protected]"
}

JSON is lightweight and easy for frontend apps to parse.


Complete Mental Model

Think of REST APIs as:

Resources + HTTP Methods

The URL identifies the resource.

The HTTP method identifies the action.


Full REST Flow Visualization

GET /users
      ↓
Server Receives Request
      ↓
Database Query
      ↓
JSON Response Returned
      ↓
Frontend Displays Data

Suggested Diagrams for Your Hashnode Article

1. CRUD vs HTTP Methods Table

Create → POST
Read   → GET
Update → PUT
Delete → DELETE

2. REST Lifecycle Diagram

Client
   ↓
HTTP Request
   ↓
REST API Server
   ↓
Database
   ↓
JSON Response
   ↓
Frontend UI

3. Resource-Based Routing

/users
/users/1
/users/1/posts

4. Request-Response Flow

Request → Server → Response

Final Thoughts

REST APIs are the backbone of modern web development.

Understanding REST helps you build:

  • Frontend applications

  • Backend services

  • Full-stack applications

  • Mobile app backends

  • Scalable APIs

The key idea is simple:

REST APIs organize communication around resources using standard HTTP methods.

Once you understand:

  • resources

  • routes

  • methods

  • status codes

you already understand the core foundation of backend communication.


Conclusion

A REST API is simply a structured way for clients and servers to communicate.

The basic flow is:

Client Request
      ↓
Server Processes
      ↓
Response Returned

Using:

  • Resources

  • HTTP methods

  • Status codes

  • Predictable routes

REST creates clean, scalable, and maintainable APIs used across the entire web.

No comments yet. Be the first to comment.