Awesome-claude-code api-design-knowledge

API Design knowledge base. Provides REST constraints, Richardson Maturity Model, HTTP semantics, content negotiation, and GraphQL/gRPC comparison for API audits and generation.

install
source · Clone the upstream repo
git clone https://github.com/dykyi-roman/awesome-claude-code
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/dykyi-roman/awesome-claude-code "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/api-design-knowledge" ~/.claude/skills/dykyi-roman-awesome-claude-code-api-design-knowledge && rm -rf "$T"
manifest: skills/api-design-knowledge/SKILL.md
source content

API Design Knowledge Base

Quick reference for API design patterns, REST best practices, and PHP implementation guidelines.

Core Principles

REST Constraints

ConstraintDescriptionImplication
Client-ServerSeparation of concernsIndependent evolution
StatelessNo server-side session stateEach request contains all info
CacheableResponses declare cacheabilityReduces server load
Uniform InterfaceStandard resource operationsPredictable API surface
Layered SystemClient can't tell if connected directlyProxy, gateway, CDN support
Code on Demand (optional)Server can send executable codeRarely used in APIs

Richardson Maturity Model

LevelNameDescriptionExample
0Swamp of POXSingle endpoint, RPC-style
POST /api
with action in body
1ResourcesMultiple endpoints per resource
GET /orders/123
2HTTP VerbsProper use of HTTP methods + status codes
DELETE /orders/123
204
3HATEOASHypermedia controls in responsesLinks to related actions

HTTP Methods Semantics

MethodSafeIdempotentRequest BodyTypical Use
GETYesYesNoRetrieve resource
HEADYesYesNoCheck resource existence
POSTNoNoYesCreate resource, trigger action
PUTNoYesYesReplace resource entirely
PATCHNoNoYesPartial update
DELETENoYesNoRemove resource
OPTIONSYesYesNoCORS preflight, capabilities

Status Code Guide

RangeCategoryCommon Codes
2xxSuccess200 OK, 201 Created, 202 Accepted, 204 No Content
3xxRedirection301 Moved Permanently, 304 Not Modified
4xxClient Error400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Conflict, 422 Unprocessable Entity, 429 Too Many Requests
5xxServer Error500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout

Content Negotiation

HeaderPurposeExample
AcceptClient requests format
Accept: application/json
Content-TypeBody format declaration
Content-Type: application/json
Accept-LanguageLocalization
Accept-Language: en-US
Accept-EncodingCompression
Accept-Encoding: gzip, br

API Style Comparison

AspectRESTGraphQLgRPC
ProtocolHTTP/1.1+HTTP/1.1+HTTP/2
Data formatJSONJSONProtobuf
SchemaOpenAPI (optional)SDL (required).proto (required)
CachingHTTP caching nativeComplex (POST only)Manual
Over-fetchingCommonSolved (client picks fields)Solved (defined messages)
Under-fetchingCommon (multiple calls)Solved (nested queries)Separate RPCs
Learning curveLowMediumHigh
Best forPublic APIs, CRUDClient-driven UIs, BFFInternal services, streaming

Quick Checklists

API Design Checklist

  • Resources use nouns, not verbs (
    /orders
    not
    /getOrders
    )
  • Consistent naming convention (kebab-case or camelCase)
  • Proper HTTP methods for operations
  • Meaningful status codes (not always 200)
  • Pagination for list endpoints
  • Filtering and sorting support
  • Versioning strategy defined
  • Error responses follow RFC 7807
  • Rate limiting with proper headers
  • CORS configured for browser clients

Security Checklist

  • Authentication on all endpoints (except public)
  • Authorization checks per resource
  • Input validation at API boundary
  • Rate limiting per client/IP
  • HTTPS only (no HTTP)
  • No sensitive data in URLs
  • Proper CORS policy
  • Security headers set

Detection Patterns

# REST endpoint definitions
Grep: "#\[Route|@Route|->get\(|->post\(|->put\(|->delete\(" --glob "**/*.php"
Glob: **/Controller/**/*.php
Glob: **/Action/**/*.php

# Status code usage
Grep: "->setStatusCode\(|Response\(.*[0-9]{3}|JsonResponse\(" --glob "**/*.php"

# Content negotiation
Grep: "Accept|Content-Type|application/json" --glob "**/*.php"

# API versioning
Grep: "/v[0-9]/|api-version|Accept.*vnd\." --glob "**/*.php"

# Error handling
Grep: "ProblemDetails|RFC7807|application/problem" --glob "**/*.php"
Grep: "JsonResponse.*4[0-9]{2}|JsonResponse.*5[0-9]{2}" --glob "**/*.php"

# Pagination
Grep: "page|per_page|limit|offset|cursor" --glob "**/Controller/**/*.php"

Advanced API Patterns

Cursor-Based Pagination (High-Load)

AspectOffset-BasedCursor-Based
URL
?page=5&per_page=20
?cursor=abc123&limit=20
Performance at scaleDegrades (OFFSET N)Constant (WHERE id > X)
ConsistencyMisses/duplicates on insertStable, no gaps
Random page accessYesNo (sequential only)
Use caseAdmin panelsFeeds, large datasets

API Rate Limiting Algorithms

AlgorithmPrecisionBurstPHP Implementation
Token BucketMediumAllows burstRedis Lua script
Sliding WindowHighSmoothRedis sorted set
Fixed WindowLowEdge burstRedis INCR + EXPIRE
Leaky BucketHighNo burstRedis list

Rate Limit Headers:

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

gRPC for PHP

FactorChoose RESTChoose gRPC
Client typeBrowser, third-partyInternal services
PayloadSmall-medium JSONLarge binary data
StreamingNot neededReal-time updates
PHP ecosystemMatureLimited (ext-grpc)

GraphQL N+1 Prevention

TechniqueHowComplexity
DataLoaderBatch + cache per requestMedium
Query depth limitMax 5-7 nesting levelsLow
Complexity scoringCost per field, reject expensiveMedium
Persisted queriesWhitelist allowed queriesLow

References

For detailed information, load these reference files:

  • references/rest-patterns.md
    — Richardson Maturity details, HATEOAS, pagination, filtering, versioning strategies
  • references/error-handling.md
    — RFC 7807 Problem Details, error response patterns, GraphQL errors, PHP implementation
  • references/advanced-api.md
    — Cursor-based pagination, API rate limiting (token bucket, sliding window), gRPC PHP integration, GraphQL N+1 solutions