All skills
asyrafhussin avatar

/api-design-patterns

@1de3a7a

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".

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/api-design-patterns

This session only. Nothing lands on disk.

rulespage-metadata.md

≈569 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Include Pagination Metadata in Responses

Impact: HIGH (Eliminates guesswork pagination and reduces unnecessary API calls by 30-50%)

Without pagination metadata, clients must make an extra request to discover there are no more results, or blindly paginate until they receive an empty response. Including metadata in every paginated response gives clients everything they need to render UI controls and make efficient decisions about fetching more data.

Incorrect

GET /api/v1/products?page=2&per_page=20
[
  { "id": 21, "name": "Widget A", "price": 9.99 },
  { "id": 22, "name": "Widget B", "price": 14.99 }
]

Problems:

  • Client cannot distinguish "page has fewer items than per_page" from "this is the last page"
  • No total count means page selector UIs and "X results found" labels are impossible
  • Client must request the next page to discover it is empty — wasting a round trip
  • No navigation links forces clients to manually construct pagination URLs

Correct

GET /api/v1/products?page=2&per_page=20
{
  "data": [
    { "id": 21, "name": "Widget A", "price": 9.99 },
    { "id": 22, "name": "Widget B", "price": 14.99 }
  ],
  "meta": {
    "current_page": 2,
    "per_page": 20,
    "total_count": 195,
    "total_pages": 10,
    "has_more": true
  },
  "links": {
    "first": "/api/v1/products?page=1&per_page=20",
    "prev": "/api/v1/products?page=1&per_page=20",
    "next": "/api/v1/products?page=3&per_page=20",
    "last": "/api/v1/products?page=10&per_page=20"
  }
}

Benefits:

  • has_more lets infinite-scroll UIs know when to stop fetching without an extra empty request
  • total_count and total_pages enable "Showing 21-40 of 195 results" display
  • Navigation links let clients follow links instead of constructing URLs, reducing coupling
  • Consistent envelope structure makes client-side deserialization predictable across all endpoints

Reference: GitHub REST API - Pagination

Source: SKILL.md on GitHub

1 alert16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill is a comprehensive documentation library for RESTful API design patterns. It provides best practices for resource design, error handling, security, and documentation. The skill contains no executable code, malicious instructions, or hidden functionality, and its references are restricted to well-known technical documentation sources.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    4/28 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 1de3a7a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago
metadata
{
  "author": "agent-skills",
  "version": "2.0.0"
}

README badge

README badge for asyrafhussin/agent-skills/api-design-patterns