Ask anything about this article
Hi! I've read this article.
What would you like to know?
@farhan

For years, the standard way to build a React application with a backend was to build a REST API. You create an endpoint like /api/users, write a fetch call on the frontend, handle loading states, handle error states, and manually invalidate caches.
It's tedious. With Next.js 15, I finally took the plunge and migrated my entire architecture to Server Actions. I deleted my /api folder entirely.
A Server Action is essentially an RPC (Remote Procedure Call). It allows you to define an asynchronous function on the server and call it directly from a client component, as if it were a normal JavaScript function.
typescript// actions.ts
'use server'
import { getDb } from '@/lib/mongodb'
export async function likePost(blogId: string) {
const db = await getDb()
await db.collection('blogs').updateOne(
{ _id: new ObjectId(blogId) },
{ $inc: { likes: 1 } }
)
return { success: true }
}
Then, on the client:
tsx// LikeButton.tsx
'use client'
import { likePost } from './actions'
export default function LikeButton({ id }) {
return <button onClick={() => likePost(id)}>Like</button>
}
useEffect, no more manual fetch wrappers, no more parsing res.json().<form> actions, meaning your app can function even before JavaScript loads.The transition requires a shift in mental models—you have to think about security at the function level rather than the endpoint level—but the increase in developer velocity is undeniable.