Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Next.js 15 App Router Architecture 20 mins read Free Lesson

Server Actions & Form Mutations without API Endpoints

Mutate database data directly from forms using 'use server' Server Actions with progressive enhancement.

Server Actions in Next.js 15

// app/actions/create-course.ts
'use server';

import { revalidatePath } from 'next/cache';

export async function addCourse(formData: FormData) {
    const title = formData.get('title');
    // Direct database write on the server!
    await db.course.create({ data: { title } });
    revalidatePath('/courses');
}