{"id":"a3aebdf0-5588-4328-9c38-d47acbd18563","shortId":"tHZAVj","kind":"skill","title":"api-design-patterns","tagline":"RESTful API design, error handling, versioning, and best practices. Use when designing APIs, reviewing endpoints, implementing error responses, or setting up API structure. Triggers on \"design API\", \"review API\", \"REST best practices\", or \"API patterns\".","description":"# API Design Patterns\n\nRESTful API design principles for building consistent, developer-friendly APIs. Contains 38 rules across 7 categories covering resource design, error handling, security, pagination, versioning, response format, and documentation.\n\n## Metadata\n\n- **Version:** 2.0.0\n- **Rule Count:** 38 rules across 7 categories\n- **License:** MIT\n\n## When to Apply\n\nReference these guidelines when:\n- Designing new API endpoints\n- Reviewing existing API structure\n- Implementing error handling and validation\n- Setting up pagination, filtering, and sorting\n- Planning API versioning strategy\n- Configuring API security (auth, CORS, rate limiting)\n- Writing API documentation (OpenAPI/Swagger)\n\n## Rule Categories by Priority\n\n| Priority | Category | Impact | Prefix |\n|----------|----------|--------|--------|\n| 1 | Resource Design | CRITICAL | `rest-` |\n| 2 | Error Handling | CRITICAL | `error-` |\n| 3 | Security | CRITICAL | `sec-` |\n| 4 | Pagination & Filtering | HIGH | `page-`, `filter-`, `sort-` |\n| 5 | Versioning | HIGH | `ver-` |\n| 6 | Response Format | MEDIUM | `resp-` |\n| 7 | Documentation | MEDIUM | `doc-` |\n\n## Quick Reference\n\n### 1. Resource Design (CRITICAL)\n\n- `rest-nouns-not-verbs` - Use nouns for endpoints, not verbs\n- `rest-plural-resources` - Use plural resource names\n- `rest-http-methods` - Correct HTTP method usage (GET, POST, PUT, PATCH, DELETE)\n- `rest-nested-resources` - Proper resource nesting (max 2 levels)\n- `rest-status-codes` - Appropriate HTTP status codes\n- `rest-idempotency` - Idempotent operations with idempotency keys\n- `rest-hateoas` - Hypermedia links for discoverability\n- `rest-resource-actions` - Non-CRUD actions as sub-resources\n\n### 2. Error Handling (CRITICAL)\n\n- `error-consistent-format` - Consistent error response structure\n- `error-meaningful-messages` - Helpful, actionable error messages\n- `error-validation-details` - Field-level validation errors\n- `error-error-codes` - Machine-readable error codes\n- `error-no-stack-traces` - Never expose stack traces in production\n- `error-request-id` - Include request IDs for debugging\n\n### 3. Security (CRITICAL)\n\n- `sec-authentication` - Proper auth implementation (OAuth2/JWT)\n- `sec-authorization` - Resource-level permissions (RBAC)\n- `sec-rate-limiting` - Prevent abuse with rate limiting\n- `sec-input-validation` - Validate and sanitize all input\n- `sec-cors-config` - CORS configuration with whitelists\n- `sec-https-only` - Enforce HTTPS for all traffic\n- `sec-sensitive-data` - Protect passwords, tokens, PII\n\n### 4. Pagination & Filtering (HIGH)\n\n- `page-cursor-based` - Cursor pagination for large datasets\n- `page-offset-based` - Offset pagination for simple cases\n- `page-consistent-params` - Consistent parameter naming\n- `page-metadata` - Include pagination metadata in responses\n- `filter-query-params` - Filter via query parameters\n- `sort-flexible` - Flexible sorting with `-` prefix for descending\n\n### 5. Versioning (HIGH)\n\n- `ver-url-path` - Version in URL path (/api/v1/)\n- `ver-header-based` - Version via Accept header\n- `ver-backward-compatible` - Maintain backward compatibility\n- `ver-deprecation` - Deprecation strategy with Sunset header\n\n### 6. Response Format (MEDIUM)\n\n- `resp-consistent-structure` - Consistent response envelope\n- `resp-json-conventions` - JSON naming conventions\n- `resp-partial-responses` - Field selection (sparse fieldsets)\n- `resp-compression` - Response compression (gzip/Brotli)\n\n### 7. Documentation (MEDIUM)\n\n- `doc-openapi` - OpenAPI/Swagger specification\n- `doc-examples` - Request/response examples\n- `doc-changelog` - API changelog\n\n## Essential Guidelines\n\n### Resource Naming\n\n```\n# ❌ Verbs in URLs\nGET    /getUsers\nPOST   /createUser\n\n# ✅ Nouns with HTTP methods\nGET    /users          # List users\nPOST   /users          # Create user\nGET    /users/123      # Get user\nPUT    /users/123      # Update user (full)\nPATCH  /users/123      # Update user (partial)\nDELETE /users/123      # Delete user\n```\n\n### Error Response Format\n\n```json\n{\n  \"error\": {\n    \"code\": \"VALIDATION_ERROR\",\n    \"message\": \"The request contains invalid data\",\n    \"details\": [\n      {\n        \"field\": \"email\",\n        \"code\": \"INVALID_FORMAT\",\n        \"message\": \"Please provide a valid email address\"\n      }\n    ],\n    \"request_id\": \"req_abc123\"\n  }\n}\n```\n\n### Pagination\n\n```json\n{\n  \"data\": [...],\n  \"meta\": {\n    \"current_page\": 2,\n    \"per_page\": 20,\n    \"total_pages\": 10,\n    \"total_count\": 195\n  },\n  \"links\": {\n    \"first\": \"/users?page=1&per_page=20\",\n    \"prev\": \"/users?page=1&per_page=20\",\n    \"next\": \"/users?page=3&per_page=20\",\n    \"last\": \"/users?page=10&per_page=20\"\n  }\n}\n```\n\n### Rate Limiting Headers\n\n```\nHTTP/1.1 200 OK\nX-RateLimit-Limit: 1000\nX-RateLimit-Remaining: 998\nX-RateLimit-Reset: 1640995200\n```\n\n## How to Use\n\nRead individual rule files for detailed explanations:\n\n```\nrules/rest-http-methods.md\nrules/error-consistent-format.md\nrules/page-cursor-based.md\nrules/sec-authentication.md\nrules/ver-url-path.md\nrules/doc-openapi.md\n```\n\n## References\n\n- [RESTful API Guidelines](https://restfulapi.net)\n- [Zalando RESTful API Guidelines](https://zalando.github.io/restful-api-guidelines)\n- [Microsoft API Guidelines](https://github.com/microsoft/api-guidelines)\n- [Google API Design Guide](https://cloud.google.com/apis/design)\n- [OpenAPI Specification](https://swagger.io/specification)\n\n## Full Compiled Document\n\nFor the complete guide with all rules expanded: `AGENTS.md`","tags":["api","design","patterns","agent","skills","asyrafhussin","agent-rules","agent-skills","ai-agents","ai-slop","claude-code","code-quality"],"capabilities":["skill","source-asyrafhussin","skill-api-design-patterns","topic-agent-rules","topic-agent-skills","topic-ai-agents","topic-ai-slop","topic-claude-code","topic-code-quality","topic-code-review","topic-codex","topic-cursor","topic-laravel","topic-nodejs","topic-react"],"categories":["agent-skills"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/AsyrafHussin/agent-skills/api-design-patterns","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add AsyrafHussin/agent-skills","source_repo":"https://github.com/AsyrafHussin/agent-skills","install_from":"skills.sh"}},"qualityScore":"0.469","qualityRationale":"deterministic score 0.47 from registry signals: · indexed on github topic:agent-skills · 39 github stars · SKILL.md body (5,460 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-18T18:58:23.889Z","embedding":null,"createdAt":"2026-05-16T18:57:13.711Z","updatedAt":"2026-05-18T18:58:23.889Z","lastSeenAt":"2026-05-18T18:58:23.889Z","tsv":"'/api/v1':434 '/apis/design)':686 '/createuser':518 '/getusers':516 '/microsoft/api-guidelines)':679 '/restful-api-guidelines)':673 '/specification)':691 '/users':524,528,598,605,612,619 '/users/123':532,536,541,546 '1':133,169,600,607 '10':592,621 '1000':635 '1640995200':645 '195':595 '2':138,213,250,586 '2.0.0':74 '20':589,603,610,617,624 '200':629 '3':143,308,614 '38':55,77 '4':147,369 '5':154,423 '6':158,458 '7':58,80,163,490 '998':640 'abc123':579 'abus':331 'accept':441 'across':57,79 'action':241,245,267 'address':575 'agents.md':703 'api':2,6,17,26,31,33,38,40,44,53,93,97,111,115,122,506,664,669,675,681 'api-design-pattern':1 'appli':86 'appropri':219 'auth':117,315 'authent':313 'author':320 'backward':445,448 'base':376,385,438 'best':12,35 'build':48 'case':390 'categori':59,81,126,130 'changelog':505,507 'cloud.google.com':685 'cloud.google.com/apis/design)':684 'code':218,222,282,287,554,566 'compat':446,449 'compil':693 'complet':697 'compress':486,488 'config':347 'configur':114,349 'consist':49,256,258,393,395,464,466 'contain':54,560 'convent':472,475 'cor':118,346,348 'correct':196 'count':76,594 'cover':60 'creat':529 'critic':136,141,145,172,253,310 'crud':244 'current':584 'cursor':375,377 'data':364,562,582 'dataset':381 'debug':307 'delet':204,545,547 'deprec':452,453 'descend':422 'design':3,7,16,30,41,45,62,91,135,171,682 'detail':273,563,654 'develop':51 'developer-friend':50 'discover':237 'doc':166,494,499,504 'doc-changelog':503 'doc-exampl':498 'doc-openapi':493 'document':71,123,164,491,694 'email':565,574 'endpoint':19,94,181 'enforc':356 'envelop':468 'error':8,21,63,100,139,142,251,255,259,263,268,271,278,280,281,286,289,300,549,553,556 'error-consistent-format':254 'error-error-cod':279 'error-meaningful-messag':262 'error-no-stack-trac':288 'error-request-id':299 'error-validation-detail':270 'essenti':508 'exampl':500,502 'exist':96 'expand':702 'explan':655 'expos':294 'field':275,480,564 'field-level':274 'fieldset':483 'file':652 'filter':107,149,152,371,407,410 'filter-query-param':406 'first':597 'flexibl':416,417 'format':69,160,257,460,551,568 'friend':52 'full':539,692 'get':200,515,523,531,533 'github.com':678 'github.com/microsoft/api-guidelines)':677 'googl':680 'guid':683,698 'guidelin':89,509,665,670,676 'gzip/brotli':489 'handl':9,64,101,140,252 'hateoa':233 'header':437,442,457,627 'help':266 'high':150,156,372,425 'http':194,197,220,521 'http/1.1':628 'https':354,357 'hypermedia':234 'id':302,305,577 'idempot':225,226,229 'impact':131 'implement':20,99,316 'includ':303,401 'individu':650 'input':337,343 'invalid':561,567 'json':471,473,552,581 'key':230 'larg':380 'last':618 'level':214,276,323 'licens':82 'limit':120,329,334,626,634 'link':235,596 'list':525 'machin':284 'machine-read':283 'maintain':447 'max':212 'meaning':264 'medium':161,165,461,492 'messag':265,269,557,569 'meta':583 'metadata':72,400,403 'method':195,198,522 'microsoft':674 'mit':83 'name':191,397,474,511 'nest':207,211 'never':293 'new':92 'next':611 'non':243 'non-crud':242 'noun':175,179,519 'oauth2/jwt':317 'offset':384,386 'ok':630 'openapi':495,687 'openapi/swagger':124,496 'oper':227 'page':151,374,383,392,399,585,588,591,599,602,606,609,613,616,620,623 'page-consistent-param':391 'page-cursor-bas':373 'page-metadata':398 'page-offset-bas':382 'pagin':66,106,148,370,378,387,402,580 'param':394,409 'paramet':396,413 'partial':478,544 'password':366 'patch':203,540 'path':429,433 'pattern':4,39,42 'per':587,601,608,615,622 'permiss':324 'pii':368 'plan':110 'pleas':570 'plural':186,189 'post':201,517,527 'practic':13,36 'prefix':132,420 'prev':604 'prevent':330 'principl':46 'prioriti':128,129 'product':298 'proper':209,314 'protect':365 'provid':571 'put':202,535 'queri':408,412 'quick':167 'rate':119,328,333,625 'ratelimit':633,638,643 'rbac':325 'read':649 'readabl':285 'refer':87,168,662 'remain':639 'req':578 'request':301,304,559,576 'request/response':501 'reset':644 'resourc':61,134,170,187,190,208,210,240,249,322,510 'resource-level':321 'resp':162,463,470,477,485 'resp-compress':484 'resp-consistent-structur':462 'resp-json-convent':469 'resp-partial-respons':476 'respons':22,68,159,260,405,459,467,479,487,550 'rest':5,34,43,137,174,185,193,206,216,224,232,239,663,668 'rest-hateoa':231 'rest-http-method':192 'rest-idempot':223 'rest-nested-resourc':205 'rest-nouns-not-verb':173 'rest-plural-resourc':184 'rest-resource-act':238 'rest-status-cod':215 'restfulapi.net':666 'review':18,32,95 'rule':56,75,78,125,651,701 'rules/doc-openapi.md':661 'rules/error-consistent-format.md':657 'rules/page-cursor-based.md':658 'rules/rest-http-methods.md':656 'rules/sec-authentication.md':659 'rules/ver-url-path.md':660 'sanit':341 'sec':146,312,319,327,336,345,353,362 'sec-authent':311 'sec-author':318 'sec-cors-config':344 'sec-https-on':352 'sec-input-valid':335 'sec-rate-limit':326 'sec-sensitive-data':361 'secur':65,116,144,309 'select':481 'sensit':363 'set':24,104 'simpl':389 'skill' 'skill-api-design-patterns' 'sort':109,153,415,418 'sort-flex':414 'source-asyrafhussin' 'spars':482 'specif':497,688 'stack':291,295 'status':217,221 'strategi':113,454 'structur':27,98,261,465 'sub':248 'sub-resourc':247 'sunset':456 'swagger.io':690 'swagger.io/specification)':689 'token':367 'topic-agent-rules' 'topic-agent-skills' 'topic-ai-agents' 'topic-ai-slop' 'topic-claude-code' 'topic-code-quality' 'topic-code-review' 'topic-codex' 'topic-cursor' 'topic-laravel' 'topic-nodejs' 'topic-react' 'total':590,593 'trace':292,296 'traffic':360 'trigger':28 'updat':537,542 'url':428,432,514 'usag':199 'use':14,178,188,648 'user':526,530,534,538,543,548 'valid':103,272,277,338,339,555,573 'ver':157,427,436,444,451 'ver-backward-compat':443 'ver-deprec':450 'ver-header-bas':435 'ver-url-path':426 'verb':177,183,512 'version':10,67,73,112,155,424,430,439 'via':411,440 'whitelist':351 'write':121 'x':632,637,642 'x-ratelimit-limit':631 'x-ratelimit-remain':636 'x-ratelimit-reset':641 'zalando':667 'zalando.github.io':672 'zalando.github.io/restful-api-guidelines)':671","prices":[{"id":"cbe88637-90e9-4d79-afef-90e01f326683","listingId":"a3aebdf0-5588-4328-9c38-d47acbd18563","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"AsyrafHussin","category":"agent-skills","install_from":"skills.sh"},"createdAt":"2026-05-16T18:57:13.711Z"}],"sources":[{"listingId":"a3aebdf0-5588-4328-9c38-d47acbd18563","source":"github","sourceId":"AsyrafHussin/agent-skills/api-design-patterns","sourceUrl":"https://github.com/AsyrafHussin/agent-skills/tree/main/skills/api-design-patterns","isPrimary":false,"firstSeenAt":"2026-05-16T18:57:13.711Z","lastSeenAt":"2026-05-18T18:58:23.889Z"}],"details":{"listingId":"a3aebdf0-5588-4328-9c38-d47acbd18563","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"AsyrafHussin","slug":"api-design-patterns","github":{"repo":"AsyrafHussin/agent-skills","stars":39,"topics":["agent-rules","agent-skills","ai-agents","ai-slop","claude-code","code-quality","code-review","codex","cursor","laravel","nodejs","react","technical-debt","typescript","windsurf"],"license":"mit","html_url":"https://github.com/AsyrafHussin/agent-skills","pushed_at":"2026-05-16T19:24:02Z","description":"Agent skills for AI coding agents (Claude Code, Cursor, Codex, Windsurf) — Laravel, React, TypeScript, MySQL, code quality, technical debt, documentation, and security.","skill_md_sha":"32945d28017fa2295e99584202e67cdaaf6eaf22","skill_md_path":"skills/api-design-patterns/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/AsyrafHussin/agent-skills/tree/main/skills/api-design-patterns"},"layout":"multi","source":"github","category":"agent-skills","frontmatter":{"name":"api-design-patterns","license":"MIT","description":"RESTful API design, error handling, versioning, and best practices. Use when designing APIs, reviewing endpoints, implementing error responses, or setting up API structure. Triggers on \"design API\", \"review API\", \"REST best practices\", or \"API patterns\"."},"skills_sh_url":"https://skills.sh/AsyrafHussin/agent-skills/api-design-patterns"},"updatedAt":"2026-05-18T18:58:23.889Z"}}