agentleFS
modu-aimodu-ai/moai-adk/.claude/skills/moai-ref-api-patterns/SKILL.md

moai-ref-api-patterns

Skill1.2k starsChanged 3 months agoApache-2.0View on GitHub

REST/GraphQL API design patterns, error handling conventions, and input validation reference for backend development. Agent-extending skill that amplifies backend domain work (spawned via Agent(general-purpose) with backend instructions) with production-grade API patterns. Use when designing APIs, implementing endpoints, or reviewing backend code. NOT for: frontend development, DevOps, database schema design, security audits.

Trending

Quiet since September.thin dataabout the whole repository

Jan 2026: 1 mentionFeb 2026: 0 mentionsMar 2026: 1 mentionApr 2026: 5 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 1 mentionAug 2026: 0 mentionsSep 2026: 3 mentionsOct 2026: 0 mentionsNov 2026: 0 mentionsDec 2026: 0 mentions
Jan 2026Jul 2026Dec 2026
Mentions a month of the modu-ai/moai-adk repository that our weekly crawl found: only 13 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Who's talking about modu-ai/moai-adk

The biggest 5 of 13 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 13

Talked about on GitHub (13 times).

On GitHub · 13

8 more on GitHub

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never expose stack traces or internal details in production

    line 87
  2. Distinctive:

    Always include request_id for traceability

    line 88
  3. Distinctive:

    Use consistent error codes (ENUM, not free text)

    line 89
  4. Distinctive:

    Hyrum's Law: Every observable API behavior will eventually be depended on by clients.

    line 173
  5. Distinctive:

    No pagination on list endpoints that can return unbounded results

    line 182

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API Patterns Reference

Target Spawn

Backend domain work spawned via Agent(general-purpose) with backend instructions - Applies these patterns directly to API implementation and review.

RESTful API Design Conventions

PrincipleConventionExample
Resource NamingPlural nouns, lowercase, kebab-case/api/v1/user-profiles
CollectionGET returns array with paginationGET /users?page=1&limit=20
Single ResourceGET returns objectGET /users/{id}
CreatePOST to collectionPOST /users
Update (full)PUT to resourcePUT /users/{id}
Update (partial)PATCH to resourcePATCH /users/{id}
DeleteDELETE to resourceDELETE /users/{id}
Nested ResourcesMax 2 levels deep/users/{id}/posts
FilteringQuery params?status=active&role=admin
SortingSort param?sort=-created_at,name
VersioningURL prefix/api/v1/, /api/v2/

HTTP Status Code Guide

CategoryCodeWhen to Use
Success200 OKSuccessful GET, PUT, PATCH, DELETE
Success201 CreatedSuccessful POST (resource created)
Success204 No ContentSuccessful DELETE (no body)
Client Error400 Bad RequestMalformed request, validation failure
Client Error401 UnauthorizedMissing or invalid authentication
Client Error403 ForbiddenAuthenticated but not authorized
Client Error404 Not FoundResource does not exist
Client Error409 ConflictResource state conflict (duplicate)
Client Error422 UnprocessableValid syntax but semantic error
Client Error429 Too ManyRate limit exceeded
Server Error500 InternalUnexpected server error
Server Error503 Service UnavailableMaintenance or overload

Error Response Format

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Input validation failed",
    "details": [
      {"field": "email", "message": "Must be a valid email address"},
      {"field": "age", "message": "Must be between 0 and 150"}
    ],
    "request_id": "req_abc123"
  }
}

Rules:

  • Never expose stack traces or internal details in production
  • Always include request_id for traceability
  • Use consistent error codes (ENUM, not free text)
  • Login failures: "Invalid email or password" (never reveal which)

Pagination Pattern

{
  "data": [...],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 150,
    "total_pages": 8,
    "has_next": true,
    "has_prev": false
  }
}

For cursor-based (large datasets):

{
  "data": [...],
  "cursor": {
    "next": "eyJpZCI6MTAwfQ==",
    "has_more": true
  }
}

Input Validation Checklist

ValidationMethodTool
Type validationSchema validationZod, Joi, pydantic, Go validator
Length limitsMin/max constraintsSchema min/max
Pattern matchingRegexEmail, URL, phone patterns
Range validationNumber/date boundsmin/max values
EnumerationAllowed valuesenum types
SQL InjectionParameterized queriesORM (Prisma, GORM, SQLAlchemy)
XSSHTML escapingTemplate engines, DOMPurify
Path TraversalPath normalizationfilepath.Clean + whitelist

Rate Limiting Strategy

TargetLimitKey
Auth endpoints5 req/minIP
General API100 req/minUser token
File upload10 req/hourUser token
Public API30 req/minIP

Response headers: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, Retry-After (on 429).

API Versioning Strategy

StrategyUse CaseExample
URL prefixMost APIs/api/v1/users
HeaderInternal APIsAccept: application/vnd.api+json; version=2
Query paramSimple APIs/users?version=2

Breaking changes that require version bump:

  • Removing or renaming fields
  • Changing field types
  • Removing endpoints
  • Changing authentication methods

Non-breaking changes (no version bump needed):

  • Adding new optional fields
  • Adding new endpoints
  • Adding new query parameters
<!-- moai:evolvable-start id="rationalizations" -->

Common Rationalizations

RationalizationReality
"REST naming conventions are just aesthetics"Consistent resource naming is how clients discover and predict endpoints. Inconsistency multiplies documentation burden.
"GraphQL solves over-fetching, so I do not need to design response shapes"GraphQL shifts complexity to the resolver layer. Poorly designed schemas create N+1 queries and authorization gaps.
"Error codes are internal details, clients just need the message"Clients need machine-readable error codes for programmatic handling. Messages are for humans, codes are for code.
"PATCH and PUT are interchangeable"PATCH applies partial updates; PUT replaces the entire resource. Using them incorrectly breaks idempotency expectations.
"I will version the API when it becomes necessary"Versioning after breaking changes forces emergency migrations. Plan versioning from the first release.

Hyrum's Law: Every observable API behavior will eventually be depended on by clients. Undocumented response fields, error formats, and timing characteristics become implicit contracts.

<!-- moai:evolvable-end --><!-- moai:evolvable-start id="red-flags" -->

Red Flags

  • API returns different error formats across endpoints
  • Resource names use verbs instead of nouns (e.g., /getUser instead of /users/:id)
  • No pagination on list endpoints that can return unbounded results
  • Breaking change deployed without API version bump
  • GraphQL schema allows unbounded depth or circular queries without limits
<!-- moai:evolvable-end --><!-- moai:evolvable-start id="verification" -->

Verification

  • All endpoints follow consistent naming convention (nouns, plurals, nested resources)
  • Error responses use a standard format with machine-readable error code
  • List endpoints implement pagination with documented limits
  • API versioning strategy present and enforced (URL path, header, or query param)
  • Breaking vs non-breaking change classification documented for recent changes
  • Input validation returns 400 with specific field-level error details
<!-- moai:evolvable-end -->

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.