Skip to content
Back to skills

Nextjs Data And Api

ASecurity

Server Actions, route handlers, data access and caching in a Next.js app. Use when adding a mutation, an API endpoint, a webhook receiver, or changing how data is fetched or cached.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 2, 2026
developmentnextjsapidatabase

Works with

  • cli
  • api

Security analysis

A100/100

Scanned December 2, 2026

npx -y skills add kinleyrabgay/coxswain --skill nextjs-data-and-api --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Nextjs Data And Api?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Nextjs Data And Api
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/kinleyrabgay-nextjs-data-and-api/badge)](https://www.skillsdirectory.com/skills/kinleyrabgay-nextjs-data-and-api)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: nextjs-data-and-api
description: Server Actions, route handlers, data access and caching in a Next.js app. Use when adding a mutation, an API endpoint, a webhook receiver, or changing how data is fetched or cached.
---
# Data, Server Actions and route handlers

## Pick the right tool
- **Server Action** (`"use server"`): mutations from your own UI (forms, buttons). Typed, no extra endpoint.
- **Route handler** (`app/api/**/route.ts`): endpoints called by others: webhooks, mobile apps, cron, public API.
- **Server Component fetch / data helper**: reads.

## Every mutation, in this order
1. **Authenticate**: get the session on the server. No session → return an unauthorised result.
2. **Validate input** with zod (or the project's validator). Coerce types; reject unknown fields.
3. **Authorise**: check the user may act on *this* record (owner, organisation membership, role). Look the record up by ID *and* tenant, never by ID alone.
4. **Do the work** through the existing data layer. Wrap multi-step writes in a transaction.
5. **Revalidate** affected paths/tags, then return a typed result (`{ ok: true, data }` / `{ ok: false, error }`). Don't throw raw errors to the client.

## Route handlers
- Export only the methods you support. Return `NextResponse.json` with correct status codes (400 validation, 401/403 auth, 404, 409 conflict).
- Read secrets from env on the server only. Never log request bodies that may contain personal data or tokens.
- Rate-limit public endpoints if the project has a limiter.

## Caching
- Know the version's default caching behaviour before relying on it. Mark per-user data as dynamic; tag shared data and revalidate the tag on writes.
- Don't cache responses that depend on cookies or headers unless keyed by them.

## Tests
- Unit-test the action/handler logic with a test database or the project's mocks: happy path, invalid input, unauthorised, wrong tenant.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.