Token导航 LogoToken导航TokenDH.com
研究检索external-servicegithub未标认证来源可访问许可证需确认审计提醒

server-actions-vs-api-optimizerserver actions VS API 优化器

Agent Skill

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

总安装

245

周安装

10

GitHub Stars

3

下载量

78
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:server-actions-vs-api-optimizer(server actions VS API 优化器)
来源仓库:https://github.com/hopeoverture/worldbuilding-app-skills
仓库路径:skills/server-actions-vs-api-optimizer
安装命令:
npx skills add https://github.com/hopeoverture/worldbuilding-app-skills --skill server-actions-vs-api-optimizer
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/hopeoverture/worldbuilding-app-skills --skill server-actions-vs-api-optimizer

简介

用于辅助 API 设计和接口文档编写。

  • 适合梳理 endpoint、生成 OpenAPI 草稿或检查字段命名。
  • 使用时需确认真实业务语义和鉴权方式。server-actions-vs-api-optimizer 属于研究检索类 Skill,可作为该场景下的辅助能力补充。
  • 涉及接口文档生成时应避免凭空补字段。
  • 最好从现有代码或样例中提取事实依据。

SKILL.md

Server Actions vs API Routes Optimizer

Analyze existing routes and recommend whether to use Server Actions or traditional API routes based on specific use case patterns, including authentication flows, data revalidation, external API calls, and client requirements.

Core Capabilities

1. Analyze Existing Routes

To analyze current route architecture:

  • Scan app directory for route handlers and Server Actions
  • Identify patterns in request/response handling
  • Detect authentication, revalidation, and external API usage
  • Use scripts/analyze_routes.py for automated analysis

2. Provide Recommendations

Based on analysis, provide recommendations using the decision matrix from references/decision_matrix.md:

  • Server Actions: Form submissions, mutations with revalidation, simple data updates
  • API Routes: External API proxying, webhooks, third-party integrations, non-form mutations
  • Hybrid Approach: Complex flows requiring both patterns

3. Generate Migration Plans

When refactoring is recommended:

  • Identify specific routes to convert
  • Provide step-by-step migration instructions
  • Show before/after code examples
  • Highlight breaking changes and client updates needed

When to Use Server Actions

Prefer Server Actions for:

  1. Form Submissions: Direct form action handling with progressive enhancement
  2. Data Mutations with Revalidation: Operations that need revalidatePath() or revalidateTag()
  3. Simple CRUD Operations: Direct database mutations from components
  4. Authentication in RSC: Auth checks in Server Components
  5. File Uploads: Handling FormData directly
  6. Optimistic Updates: Client-side optimistic UI with server validation

Benefits:

  • Automatic POST request handling
  • Built-in CSRF protection
  • Type-safe with TypeScript
  • Progressive enhancement (works without JS)
  • Direct access to server-side resources
  • Simpler code for common patterns

When to Use API Routes

Prefer API routes for:

  1. External API Proxying: Hiding API keys, rate limiting, response transformation
  2. Webhooks: Third-party service callbacks (Stripe, GitHub, etc.)
  3. Non-POST Operations: GET, PUT, DELETE, PATCH endpoints
  4. Third-Party Integrations: OAuth callbacks, external service authentication
  5. Public APIs: Endpoints called by external clients
  6. Complex Response Headers: Custom headers, cookies, redirects
  7. Non-Form Client Requests: fetch() calls from client components
  8. SSE/Streaming: Server-sent events or custom streaming

Benefits:

  • Full HTTP method support
  • Custom response handling
  • External accessibility
  • Middleware support
  • Standard REST API patterns

Analysis Workflow

1. Run Automated Analysis

Use the analysis script to scan your codebase:

python scripts/analyze_routes.py --path /path/to/app --output analysis-report.md

The script identifies:

  • Existing API routes and their patterns
  • Server Actions usage
  • Authentication patterns
  • Revalidation calls
  • External API integrations
  • Potential optimization opportunities

2. Review Decision Matrix

Consult references/decision_matrix.md for detailed decision criteria:

  • Use case patterns
  • Trade-offs analysis
  • Performance considerations
  • Security implications
  • Developer experience factors

3. Generate Recommendations

For each route, determine:

  • Current implementation pattern
  • Recommended pattern (Server Action or API route)
  • Reasoning based on use case
  • Migration complexity (low/medium/high)
  • Potential benefits of refactoring

4. Create Migration Plan

For routes requiring changes:

  • Prioritize high-impact, low-complexity migrations
  • Document breaking changes
  • Provide code transformation examples
  • Update client-side code if needed

Common Patterns and Recommendations

Pattern: Form Submission with DB Update

Current: API route with fetch from client Recommended: Server Action Reason: Simpler, built-in CSRF protection, progressive enhancement

// Before (API Route)
// app/api/entities/route.ts
export async function POST(request: Request) {
  const data = await request.json();
  await db.entity.create(data);
  return Response.json({ success: true });
}

// After (Server Action)
// app/actions.ts
'use server';
export async function createEntity(formData: FormData) {
  await db.entity.create(Object.fromEntries(formData));
  revalidatePath('/entities');
}

Pattern: External API Proxy

Current: Client-side fetch to external API (exposes keys) Recommended: API route Reason: Hide API keys, rate limiting, response transformation

// Recommended: API Route
// app/api/external-service/route.ts
export async function GET(request: Request) {
  const { searchParams } = new URL(request.url);
  const query = searchParams.get('query');

  const response = await fetch(`https://api.external.com?key=${process.env.API_KEY}&q=${query}`);
  const data = await response.json();

  return Response.json(data);
}

Pattern: Webhook Handler

Current: None (new feature) Recommended: API route Reason: External service calls, needs public URL

// Recommended: API Route
// app/api/webhooks/stripe/route.ts
export async function POST(request: Request) {
  const signature = request.headers.get('stripe-signature');
  const body = await request.text();

  // Verify webhook signature
  // Process webhook event

  return Response.json({ received: true });
}

Pattern: Data Mutation with Revalidation

Current: API route with manual cache invalidation Recommended: Server Action Reason: Built-in revalidation, simpler code

// Before (API Route)
// app/api/entities/[id]/route.ts
export async function PATCH(request: Request, { params }) {
  const data = await request.json();
  await db.entity.update({ where: { id: params.id }, data });
  revalidatePath('/entities');
  return Response.json({ success: true });
}

// After (Server Action)
// app/actions.ts
'use server';
export async function updateEntity(id: string, data: any) {
  await db.entity.update({ where: { id }, data });
  revalidatePath('/entities');
  revalidateTag(`entity-${id}`);
}

Pattern: Authentication Check

Current: API middleware Recommended: Server Action for mutations, API route for public endpoints Reason: Simpler auth in Server Components

// Server Action (for mutations)
'use server';
export async function protectedAction() {
  const session = await auth();
  if (!session) throw new Error('Unauthorized');
  // Perform action
}

// API Route (for public/external access)
export async function POST(request: Request) {
  const token = request.headers.get('authorization');
  if (!validateToken(token)) {
    return Response.json({ error: 'Unauthorized' }, { status: 401 });
  }
  // Process request
}

Resource Files

scripts/analyze_routes.py

Automated route analysis tool that scans your Next.js app directory to identify route patterns, Server Actions, authentication usage, revalidation calls, and external API integrations. Generates a detailed report with recommendations.

references/decision_matrix.md

Comprehensive decision matrix with detailed criteria for choosing between Server Actions and API routes. Includes use case patterns, trade-offs, performance considerations, security implications, and real-world examples.

Best Practices

  1. Default to Server Actions for Forms: Simpler, more secure, better UX
  2. Use API Routes for External Integration: Webhooks, proxies, third-party APIs
  3. Consider Progressive Enhancement: Server Actions work without JavaScript
  4. Optimize for Revalidation: Server Actions have built-in revalidation
  5. Evaluate Client Requirements: If external clients need access, use API routes
  6. Think About Method Requirements: Non-POST operations need API routes
  7. Consider Type Safety: Server Actions are fully type-safe
  8. Plan for Migration: Start with new features, gradually refactor existing

Integration with Worldbuilding App

Common patterns in worldbuilding applications:

Entity CRUD Operations

  • Create/Update/Delete entities: Server Actions (form submissions with revalidation)
  • Get entity list for external dashboard: API route (external client access)

Relationship Management

  • Add/remove relationships: Server Actions (mutations with revalidation)
  • Export relationship graph: API route (complex response, streaming)

Timeline Operations

  • Create/edit timeline events: Server Actions (form submissions)
  • Timeline data feed for visualization: API route (GET requests, caching)

Search and Filtering

  • Filter entities in app: Server Actions (with revalidation)
  • Public search API: API route (external access, rate limiting)

Import/Export

  • Import data files: Server Action (FormData handling)
  • Export to external format: API route (custom headers, streaming)

Consult references/decision_matrix.md for detailed analysis of each pattern.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

38.46%
按下载量换算30

Claude

29.71%
按下载量换算23

Cursor

19.84%
按下载量换算15

Gemini CLI

8.73%
按下载量换算7

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

通过

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills