Get the FREE Ultimate OpenClaw Setup Guide →

rest-patterns

npx machina-cli add skill aiskillstore/marketplace/rest-patterns --openclaw
Files (1)
SKILL.md
2.9 KB

REST Patterns

Quick reference for RESTful API design patterns and HTTP semantics.

HTTP Methods

MethodPurposeIdempotentCacheable
GETRetrieve resource(s)YesYes
POSTCreate new resourceNoNo
PUTReplace entire resourceYesNo
PATCHPartial updateMaybeNo
DELETERemove resourceYesNo

Essential Status Codes

CodeNameUse
200OKSuccess with body
201CreatedPOST success (add Location header)
204No ContentSuccess, no body
400Bad RequestInvalid syntax
401UnauthorizedNot authenticated
403ForbiddenNot authorized
404Not FoundResource doesn't exist
422UnprocessableValidation error
429Too Many RequestsRate limited
500Server ErrorInternal failure

Resource Design

GET    /users              # List
POST   /users              # Create
GET    /users/{id}         # Get one
PUT    /users/{id}         # Replace
PATCH  /users/{id}         # Update
DELETE /users/{id}         # Delete

# Query parameters
GET /users?page=2&limit=20          # Pagination
GET /users?sort=created_at:desc     # Sorting
GET /users?role=admin               # Filtering

Security Checklist

  • HTTPS/TLS only
  • OAuth 2.0 or JWT for auth
  • Validate all inputs
  • Rate limit per client
  • CORS headers configured
  • No sensitive data in URLs
  • Use no-store for sensitive responses

Common Mistakes

MistakeFix
Verbs in URLs/getUsers/users
Deep nestingFlatten or use query params
200 for errorsUse proper 4xx/5xx
No paginationAlways paginate collections
Missing rate limitsProtect against abuse

Quick Reference

TaskPattern
Paginate?page=2&limit=20
Sort?sort=field:asc
Filter?status=active
Sparse fields?fields=id,name
Include related?include=orders

When to Use

  • Designing new API endpoints
  • Choosing HTTP methods and status codes
  • Implementing caching headers
  • Setting up rate limiting
  • Structuring error responses

Additional Resources

For detailed patterns, load:

  • ./references/status-codes.md - Complete status code reference with examples
  • ./references/caching-patterns.md - Cache-Control, ETag, CDN patterns
  • ./references/rate-limiting.md - Rate limiting strategies and headers
  • ./references/response-formats.md - Errors, versioning, bulk ops, HATEOAS

Source

git clone https://github.com/aiskillstore/marketplace/blob/main/skills/0xdarkmatter/rest-patterns/SKILL.mdView on GitHub

Overview

Quick reference for RESTful API design patterns, HTTP semantics, caching, and rate limiting. It helps teams select appropriate methods, status codes, and query patterns to build scalable, predictable APIs.

How This Skill Works

HTTP methods map to resource operations (GET for read, POST for create, PUT/PATCH for updates, DELETE for removal). The guide enumerates status codes, and shows common query params for pagination, sorting, and filtering, plus security considerations and common mistakes to avoid in REST design.

When to Use It

  • Designing new API endpoints with RESTful conventions.
  • Choosing HTTP methods and status codes for resources.
  • Implementing caching headers and cache validation strategies.
  • Setting up rate limiting to protect APIs from abuse.
  • Structuring endpoints with pagination, sorting, and filtering.

Quick Start

  1. Step 1: Define resource endpoints and map HTTP methods (GET, POST, PUT, PATCH, DELETE).
  2. Step 2: Specify status codes, pagination, sorting, and filtering patterns (e.g., ?page=2&limit=20, ?sort=created_at:desc).
  3. Step 3: Implement caching and rate limiting, validate inputs, and secure transport.

Best Practices

  • Use proper HTTP verbs (GET, POST, PUT, PATCH, DELETE) and ensure idempotence where applicable.
  • Return appropriate status codes (200/201/204/4xx/5xx) and avoid 200s for errors.
  • Paginate collections and support ?page, ?limit, ?sort, and ?filter query params.
  • Apply rate limiting per client and respond with 429 when limits are exceeded.
  • Use caching headers (Cache-Control, ETag) and secure transport (HTTPS).

Example Use Cases

  • GET /users to list users with ?page and ?limit
  • POST /users to create a user (with Location header pointing to /users/{id})
  • GET /users/{id} to fetch a single user
  • PUT /users/{id} to replace a user resource
  • PATCH /users/{id} to partially update a user

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers