astro-actions
Astro Actions Expert
Type-safe server functions with automatic validation, standardized errors, and progressive enhancement.
Agent Workflow (MANDATORY)
Before ANY implementation, use TeamCreate to spawn 3 agents:
- fuse-ai-pilot:explore-codebase - Check existing actions in
src/actions/ - fuse-ai-pilot:research-expert - Verify latest Actions docs via Context7/Exa
- mcp__context7__query-docs - Get defineAction and ActionError examples
After implementation, run fuse-ai-pilot:sniper for validation.
Overview
When to Use
- Handling form submissions with server-side validation
- Creating type-safe backend mutations without API boilerplate
- Building progressive enhancement (works without JS)
- Replacing API endpoints for client-server communication
Why Astro Actions
| Feature | Benefit |
|---|---|
defineAction() |
Type-safe server function definition |
| Zod validation | Automatic JSON and FormData parsing |
ActionError |
Standardized error codes and messages |
accept: 'form' |
Direct HTML form submission support |
| Progressive enhancement | Works without JavaScript enabled |
astro:actions |
Client import for type-safe calls |
Core Concepts
Action Structure
All actions live in src/actions/index.ts and export a server object:
// src/actions/index.ts
import { defineAction } from 'astro:actions';
import { z } from 'astro/zod';
export const server = {
myAction: defineAction({ /* ... */ })
}
Accept Modes
| Mode | Description |
|---|---|
accept: 'json' (default) |
Parses JSON request body |
accept: 'form' |
Parses HTML FormData directly |
Error Codes
Standard HTTP-aligned codes: UNAUTHORIZED, FORBIDDEN, NOT_FOUND, BAD_REQUEST, INTERNAL_SERVER_ERROR, CONFLICT, TOO_MANY_REQUESTS.
Reference Guide
| Need | Reference |
|---|---|
| Concepts & architecture | overview.md |
| defineAction patterns | defining-actions.md |
| ActionError handling | error-handling.md |
| HTML form integration | forms.md |
| Progressive enhancement | progressive-enhancement.md |
| Contact form template | templates/contact-form.md |
| JSON action template | templates/json-action.md |
Best Practices
- Always define
inputschema — Never skip Zod validation - Use
ActionErrorfor known errors — Standardized codes for client handling accept: 'form'for HTML forms — Native form submission support- Progressive enhancement — Form works without JS, enhanced with it
- Check
ctx.cookiesfor auth — ThrowUNAUTHORIZEDwhen not logged in
More from fusengine/agents
laravel-architecture
Design Laravel app architecture with services, repositories, actions, and clean code patterns. Use when structuring projects, creating services, implementing DI, or organizing code layers.
97laravel-blade
Create Blade templates with components, slots, layouts, and directives. Use when building views, reusable components, or templating.
88laravel-livewire
Livewire 3 reactive components - wire:model, actions, events, Volt, Folio. Use when building reactive UI without JavaScript.
86nextjs-i18n
Next.js 16 internationalization with next-intl or DIY. Use when implementing i18n, translations, localization, multilingual, language switch, locale routing, or formatters.
59solid-php
SOLID principles for Laravel 12 and PHP 8.5. Files < 100 lines, interfaces separated, PHPDoc mandatory. Auto-detects Laravel and FuseCore architecture.
51laravel-testing
Write tests with Pest 3/PHPUnit, feature tests, unit tests, mocking, fakes, and factories. Use when testing controllers, services, models, or implementing TDD.
50