Next.js App Router in Depth
LESSON 4.1

Writing your first server action

Learn key techniques and workflows in Next.js App Router in Depth.

7m
intermediate
9,758 students

Overview

A server action is a function that only ever runs on the server but can be called from the client. It replaces the route handler you would otherwise write by hand.

In this lesson you will:

  • Define an action and call it from a form or an event
  • Revalidate the affected data after a write
  • Keep write credentials on the server side of the call

Pro Tip

Use caching and revalidation wisely to ensure your app stays fast and data remains fresh without unnecessary requests.

Resources