Performance: API routes vs server actions decision
MEDIUM IMPACT
This affects server response time and client-side rendering speed by choosing how backend logic is executed and data is fetched.
export async function serverAction() { const data = await fetchFromDatabase(); return data; } // Called directly from server components or client with server action support
export async function GET(request) { // API route handler const data = await fetchFromDatabase(); return new Response(JSON.stringify(data)); } // Client fetches data via fetch('/api/data')
| Pattern | Network Requests | Server Processing | Client Wait Time | Verdict |
|---|---|---|---|---|
| API Routes | 1 extra HTTP request | Separate server handler | Client waits for response | [X] Bad |
| Server Actions | No extra HTTP request | Inline server logic | Minimal client wait | [OK] Good |