PUBLIC FOLDERS
Notes in “Web”
REST API vs GraphQL — Which One Should You Really Use?
Published Dec 28, 2025

If you’ve worked with modern web or mobile applications, you’ve probably heard this debate again and again:

“Should I use REST or GraphQL?”

Blogs, YouTube videos, and Twitter threads argue endlessly — but most explanations are either too shallow or overly technical.
Let’s break it down clearly, practically, and without hype.

What Is REST (In Simple Words)?

REST (Representational State Transfer) is an API design style where:

  • Each resource has a fixed endpoint
  • You use HTTP methods like GET,POST,PUT,DELETE
  • The server decides the response structure

Example

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

Each endpoint returns a predefined data shape.

Why REST Became Popular

  • Easy to understand
  • Simple to cache
  • Works well with HTTP standards
  • Supported everywhere

What Is GraphQL?

GraphQL is a query language for APIs where:

  • There is usually one endpoint
  • The client decides what data it wants
  • The server returns exactly that

Example

{  user(id: 1) {    name    posts {      title    }  } } 

You get only what you ask for — nothing more, nothing less.


The Core Confusion: Overfetching vs Underfetching

This is where most people get stuck.

REST Problem

You often get:

  • Too much data (overfetching)
  • Too little data (underfetching → more API calls)

Example:
You want only a user’s name but get email, address, preferences, settings, etc.

GraphQL Solution

  • Client controls the response
  • One request can fetch deeply nested data
  • No wasted bandwidth

REST vs GraphQL (Quick Comparison)

FeatureRESTGraphQL
EndpointsMultipleUsually one
Data ControlServerClient
OverfetchingCommonRare
Learning CurveLowMedium
CachingSimpleMore complex
ToolingMatureRapidly growing

When REST Is the Better Choice

Use REST if:

  • Your API is simple
  • You want easy caching
  • You’re building CRUD-heavy apps
  • You need fast onboarding for developers

👉 Example: Blogs, admin dashboards, internal tools


When GraphQL Shines

Use GraphQL if:

  • You have multiple clients (web, mobile, IoT)
  • Your data is deeply connected
  • Network performance matters
  • Frontend needs flexibility

 Example: Social networks, large-scale SaaS apps


A Common Myth (Important)

“GraphQL will replace REST”
No. They solve different problems.

Many companies use:

  • REST for public APIs
  • GraphQL for internal or frontend-facing APIs

You don’t need to choose sides — choose use cases.


Final Verdict

Ask this one question before choosing:

Who should control the data shape — the server or the client?

  • Server control → REST
  • Client control → GraphQL

That’s it. Everything else is implementation detail.

JWT Authentication: What Actually Happens When You Log In
Published Dec 28, 2025

You open a website.
You enter your email and password.
You click Login.

And magically—you’re in.

No page refresh. No password sent again. You can reload the page, open a new tab, even close the browser and come back… still logged in.

Most people say:

“Yeah, that’s JWT.”

But what actually happens?

Let’s break it down in plain human language, step by step—no buzzwords, no fake complexity.


Step 1: You Send Your Credentials (Only Once)

When you click Login, your browser sends this to the server:

 

{
  "email": "[email protected]",
  "password": "secret123" 
} 

Important detail 👉 this is the only time your password is sent.

The server:

  • Finds your user
  • Verifies the password (usually via hashing)
  • Decides: Yes, this user is legit

If the password is wrong → login fails
If correct → move to the next step


Step 2: The Server Creates a JWT

Instead of saving a session in memory (old-school way), the server creates a JWT (JSON Web Token).

Think of a JWT like a digitally signed ID card.

Inside the token:

  • User ID
  • Email / username
  • Token expiry time
  • Sometimes roles or permissions

Example (simplified):

 

{
  "user_id": 42,
  "email": "[email protected]",
  "exp": 1735689600 } 

This data is:

  • Encoded
  • Signed (so it can’t be tampered with)

🔐 The server signs it using a secret key only it knows.


Step 3: Token Is Sent Back to Your Browser

The server responds:


{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." 
} 

Now your browser stores this token:

  • Usually in localStorage
  • Or cookies (more secure if done right)

From this moment on:
👉 Your token is your identity


Step 4: Every Request Includes the Token

Now when you request anything protected:

  • /profile
  • /notes
  • /dashboard

Your browser automatically sends:

Authorization: Bearer <JWT_TOKEN> 

No password.
No login again.
Just the token.


Step 5: Server Verifies the Token (Every Time)

For each request, the server:

  1. Checks the token signature
  2. Verifies it hasn’t expired
  3. Extracts user info
  4. Allows or denies access

⚠️ No database lookup is required for sessions
That’s why JWT is called stateless authentication.


Why JWT Feels So Fast

Because:

  • No session storage
  • No server memory tracking
  • No sticky sessions needed
  • Easy to scale across multiple servers

This is why JWT is popular in:

  • APIs
  • Microservices
  • Mobile apps
  • SPAs (React, Vue, etc.)

The Part People Don’t Tell You

JWT is not magic. It has trade-offs.

❌ You Can’t “Log Out” Easily

Once issued, a JWT is valid until it expires.

Logout usually means:

  • Deleting token on client
  • Or maintaining a token blacklist (extra complexity)

❌ Token Theft Is Dangerous

If someone steals your token:
👉 They are you

That’s why:

  • HTTPS is mandatory
  • Tokens should expire quickly
  • Refresh tokens must be protected

Access Token vs Refresh Token (Quickly Explained)

Good systems use two tokens:

Access Token

  • Short-lived (5–15 minutes)
  • Used on every request

Refresh Token

  • Long-lived
  • Used only to get a new access token

This way:

  • Even if access token leaks, damage is limited
  • Users stay logged in smoothly

When JWT Is a Bad Idea

JWT is NOT ideal if:

  • You need instant logout everywhere
  • You want simple auth for a small app
  • You don’t understand token security well

In those cases:
👉 Traditional session-based auth is safer and simpler.


The Big Picture

JWT is not about being “modern”.
It’s about who carries the authentication state.

  • Sessions → server remembers you
  • JWT → you carry proof of who you are

Neither is wrong.
Both are tools.


Final Thought

If you understand this flow, you already know more JWT than most developers who use it daily.