Designing apis skill

Designs REST and GraphQL APIs including endpoints, error handling, versioning, and documentation.

by CloudAI-X·MIT license·★ 1,416 Stars on the repo·GitHub ↗

Use now

Files of Designing apis

CloudAI-X/main1 file shown
SKILL.md
Show the full text230 lines

Designing APIs

When to Load
  • Trigger: Designing REST or GraphQL endpoints, API contracts, versioning, request/response formats
  • Skip: Internal-only code with no API surface

API Design Workflow

Copy this checklist and track progress:

API Design Progress:
- [ ] Step 1: Define resources and relationships
- [ ] Step 2: Design endpoint structure
- [ ] Step 3: Define request/response formats
- [ ] Step 4: Plan error handling
- [ ] Step 5: Add authentication/authorization
- [ ] Step 6: Document with OpenAPI spec
- [ ] Step 7: Validate design against checklist

REST API Design

URL Structure
# Resource-based URLs (nouns, not verbs)
GET    /users              # List users
GET    /users/:id          # Get user
POST   /users              # Create user
PUT    /users/:id          # Replace user
PATCH  /users/:id          # Update user
DELETE /users/:id          # Delete user

# Nested resources
GET    /users/:id/orders   # User's orders
POST   /users/:id/orders   # Create order for user

# Query parameters for filtering/pagination
GET    /users?role=admin&status=active
GET    /users?page=2&limit=20&sort=-createdAt
HTTP Status Codes
Code Meaning Use Case
200 OK Successful GET, PUT, PATCH
201 Created Successful POST
204 No Content Successful DELETE
400 Bad Request Invalid input
401 Unauthorized Missing/invalid auth
403 Forbidden Valid auth, no permission
404 Not Found Resource doesn't exist
409 Conflict Duplicate, state conflict
422 Unprocessable Validation failed
429 Too Many Requests Rate limited
500 Internal Error Server error
Response Formats

Success Response:

{
  "data": {
    "id": "123",
    "type": "user",
    "attributes": {
      "name": "John Doe",
      "email": "[email protected]"
    }
  },
  "meta": {
    "requestId": "abc-123"
  }
}

List Response with Pagination:

{
  "data": [...],
  "meta": {
    "total": 100,
    "page": 1,
    "limit": 20,
    "totalPages": 5
  },
  "links": {
    "self": "/users?page=1",
    "next": "/users?page=2",
    "last": "/users?page=5"
  }
}

Error Response:

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid input data",
    "details": [
      {
        "field": "email",
        "message": "Must be a valid email address"
      }
    ]
  },
  "meta": {
    "requestId": "abc-123"
  }
}

API Versioning

URL Versioning (Recommended):

/api/v1/users
/api/v2/users

Header Versioning:

Accept: application/vnd.example.v1+json

Authentication Patterns

JWT Bearer Token:

Authorization: Bearer eyJhbGciOiJIUzI1NiIs...

API Key:

X-API-Key: your-api-key

Rate Limiting Headers

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1609459200
Retry-After: 60

GraphQL Patterns

Schema Design:

# Abbreviated: input, connection and error types omitted for brevity
type Query {
  user(id: ID!): User
  users(filter: UserFilter, pagination: Pagination): UserConnection!
}

type Mutation {
  createUser(input: CreateUserInput!): UserPayload!
  updateUser(id: ID!, input: UpdateUserInput!): UserPayload!
}

type User {
  id: ID!
  name: String!
  email: String!
  orders(first: Int, after: String): OrderConnection!
}

input CreateUserInput {
  name: String!
  email: String!
}

type UserPayload {
  user: User
  errors: [Error!]
}

OpenAPI Specification Template

See OPENAPI-TEMPLATE.md for the full OpenAPI 3.0 specification template.

API Design Validation

After completing the design, validate against this checklist:

Validation Checklist:
- [ ] All endpoints use nouns, not verbs
- [ ] HTTP methods match operations correctly
- [ ] Consistent response format across endpoints
- [ ] Error responses include actionable details
- [ ] Pagination implemented for list endpoints
- [ ] Authentication defined for protected endpoints
- [ ] Rate limiting headers documented
- [ ] OpenAPI spec is complete and valid

If validation fails, return to the relevant design step and address the issues.

Security Checklist

  • HTTPS only
  • Authentication on all endpoints
  • Authorization checks
  • Input validation
  • Rate limiting
  • Request size limits
  • CORS properly configured
  • No sensitive data in URLs
  • Audit logging
1---
2name: designing-apis
3description: Designs REST and GraphQL APIs including endpoints, error handling, versioning, and documentation. Use when creating new APIs, designing endpoints, reviewing API contracts, or when asked about REST, GraphQL, or API patterns.
4---
5 
6# Designing APIs
7 
8### When to Load
9 
10- **Trigger**: Designing REST or GraphQL endpoints, API contracts, versioning, request/response formats
11- **Skip**: Internal-only code with no API surface
12 
13## API Design Workflow
14 
15Copy this checklist and track progress:
16 
17```
18API Design Progress:
19- [ ] Step 1: Define resources and relationships
20- [ ] Step 2: Design endpoint structure
21- [ ] Step 3: Define request/response formats
22- [ ] Step 4: Plan error handling
23- [ ] Step 5: Add authentication/authorization
24- [ ] Step 6: Document with OpenAPI spec
25- [ ] Step 7: Validate design against checklist
26```
27 
28## REST API Design
29 
30### URL Structure
31 
32```
33# Resource-based URLs (nouns, not verbs)
34GET /users # List users
35GET /users/:id # Get user
36POST /users # Create user
37PUT /users/:id # Replace user
38PATCH /users/:id # Update user
39DELETE /users/:id # Delete user
40 
41# Nested resources
42GET /users/:id/orders # User's orders
43POST /users/:id/orders # Create order for user
44 
45# Query parameters for filtering/pagination
46GET /users?role=admin&status=active
47GET /users?page=2&limit=20&sort=-createdAt
48```
49 
50### HTTP Status Codes
51 
52| Code | Meaning | Use Case |
53| ---- | ----------------- | -------------------------- |
54| 200 | OK | Successful GET, PUT, PATCH |
55| 201 | Created | Successful POST |
56| 204 | No Content | Successful DELETE |
57| 400 | Bad Request | Invalid input |
58| 401 | Unauthorized | Missing/invalid auth |
59| 403 | Forbidden | Valid auth, no permission |
60| 404 | Not Found | Resource doesn't exist |
61| 409 | Conflict | Duplicate, state conflict |
62| 422 | Unprocessable | Validation failed |
63| 429 | Too Many Requests | Rate limited |
64| 500 | Internal Error | Server error |
65 
66### Response Formats
67 
68**Success Response:**
69 
70```json
71{
72 "data": {
73 "id": "123",
74 "type": "user",
75 "attributes": {
76 "name": "John Doe",
77 "email": "[email protected]"
78 }
79 },
80 "meta": {
81 "requestId": "abc-123"
82 }
83}
84```
85 
86**List Response with Pagination:**
87 
88```json
89{
90 "data": [...],
91 "meta": {
92 "total": 100,
93 "page": 1,
94 "limit": 20,
95 "totalPages": 5
96 },
97 "links": {
98 "self": "/users?page=1",
99 "next": "/users?page=2",
100 "last": "/users?page=5"
101 }
102}
103```
104 
105**Error Response:**
106 
107```json
108{
109 "error": {
110 "code": "VALIDATION_ERROR",
111 "message": "Invalid input data",
112 "details": [
113 {
114 "field": "email",
115 "message": "Must be a valid email address"
116 }
117 ]
118 },
119 "meta": {
120 "requestId": "abc-123"
121 }
122}
123```
124 
125## API Versioning
126 
127**URL Versioning (Recommended):**
128 
129```
130/api/v1/users
131/api/v2/users
132```
133 
134**Header Versioning:**
135 
136```
137Accept: application/vnd.example.v1+json
138```
139 
140## Authentication Patterns
141 
142**JWT Bearer Token:**
143 
144```
145Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
146```
147 
148**API Key:**
149 
150```
151X-API-Key: your-api-key
152```
153 
154## Rate Limiting Headers
155 
156```
157X-RateLimit-Limit: 100
158X-RateLimit-Remaining: 95
159X-RateLimit-Reset: 1609459200
160Retry-After: 60
161```
162 
163## GraphQL Patterns
164 
165**Schema Design:**
166 
167```graphql
168# Abbreviated: input, connection and error types omitted for brevity
169type Query {
170 user(id: ID!): User
171 users(filter: UserFilter, pagination: Pagination): UserConnection!
172}
173 
174type Mutation {
175 createUser(input: CreateUserInput!): UserPayload!
176 updateUser(id: ID!, input: UpdateUserInput!): UserPayload!
177}
178 
179type User {
180 id: ID!
181 name: String!
182 email: String!
183 orders(first: Int, after: String): OrderConnection!
184}
185 
186input CreateUserInput {
187 name: String!
188 email: String!
189}
190 
191type UserPayload {
192 user: User
193 errors: [Error!]
194}
195```
196 
197## OpenAPI Specification Template
198 
199See [OPENAPI-TEMPLATE.md](OPENAPI-TEMPLATE.md) for the full OpenAPI 3.0 specification template.
200 
201## API Design Validation
202 
203After completing the design, validate against this checklist:
204 
205```
206Validation Checklist:
207- [ ] All endpoints use nouns, not verbs
208- [ ] HTTP methods match operations correctly
209- [ ] Consistent response format across endpoints
210- [ ] Error responses include actionable details
211- [ ] Pagination implemented for list endpoints
212- [ ] Authentication defined for protected endpoints
213- [ ] Rate limiting headers documented
214- [ ] OpenAPI spec is complete and valid
215```
216 
217If validation fails, return to the relevant design step and address the issues.
218 
219## Security Checklist
220 
221- [ ] HTTPS only
222- [ ] Authentication on all endpoints
223- [ ] Authorization checks
224- [ ] Input validation
225- [ ] Rate limiting
226- [ ] Request size limits
227- [ ] CORS properly configured
228- [ ] No sensitive data in URLs
229- [ ] Audit logging
230 

Discussion

Alternatives

API and interface designGuides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.Coding · MITContext7Pulls up-to-date, version-specific library docs and code examples into the prompt so the AI stops inventing old APIs.Coding · MITContext7 Documentation LookupFetch up-to-date documentation and code examples for any library, framework, SDK, CLI tool, or cloud service. Use whenever the user asks about a specific library — even well-known ones like React, Next.js, Prisma, Express, Tailwind, Django, or Spring Boot — because training data may not reflect recent API changes or version updates. Always use for: API syntax questions, configuration options, version migration issues, "how do I" questions mentioning a library name, debugging that involves library-specific behavior, setup instructions, and CLI tool usage. Use even when you think you know the answer. Do not rely on training data for API details, signatures, or configuration options — they are frequently out of date. Prefer this over web search for library documentation.Coding · MITAdaptyv Bio Foundry APIHow to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.Science · MIT