Route HandlersAdvanced
1Question 1 of 1
typescriptHow do Server Actions perform form mutations without API routes in Next.js?
Explanation & Concept
Server Actions are asynchronous functions that execute directly on the server, invoked from forms or event handlers. Annotated with `'use server'`.
They eliminate the need to write separate REST API endpoints for form submissions.
Code Example
typescript
// app/actions.ts
"use server";
import { revalidatePath } from "next/cache";
export async function createPost(formData: FormData) {
const title = formData.get("title");
await saveToDatabase({ title });
revalidatePath("/posts"); // Invalidate cache and update UI
}
// In component:
// <form action={createPost}><input name="title" /><button>Submit</button></form>How It Works & Key Takeaways
Server Actions work with progressive enhancement: forms can submit even if JavaScript has not finished loading on the client.
Mock Test · 1 Questions · Optional
Ready for Streaming & Suspense?
Take a quick test to evaluate yourself, or move straight to the next module.
Advanced1 questions