Skip to content

prefer-server-actions

Prefer Next.js Server Actions over same-origin API mutations.

Why

Server Actions can remove a hand-written internal API wrapper while retaining typed application calls. Client invocations still cross a network and serialization boundary.

Fix

Consider a Server Action for application-owned mutations; preserve authorization, input validation and any public API consumers.

Examples

Before — flagged Do not mutate through an API route
app/tasks/page.tsx
"use client";
await fetch("/api/tasks", { method: "POST", body });
After — preferred Call a Server Action
app/tasks/page.tsx
import { createTask } from "./actions";
await createTask(input);

Options

{
"additionalProperties": false,
"properties": {
"basePath": {
"pattern": "^/(?!$)(?!.*[?#])(?!(?:.*/)?\\.\\.?(?:/|$))(?:[^/]+/)*[^/]+$",
"type": "string"
}
},
"type": "object"
}