moicle 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/assets/architecture/go-backend.md +930 -108
- package/assets/commands/brainstorm.md +1 -0
- package/assets/skills/api-integration/SKILL.md +883 -0
- package/assets/skills/deprecation/SKILL.md +923 -0
- package/assets/skills/documentation/SKILL.md +1333 -0
- package/assets/skills/fix-pr-comment/SKILL.md +283 -0
- package/assets/skills/go-module/SKILL.md +77 -0
- package/assets/skills/incident-response/SKILL.md +946 -0
- package/assets/skills/onboarding/SKILL.md +607 -0
- package/assets/skills/pr-review/SKILL.md +620 -0
- package/assets/skills/refactor/SKILL.md +756 -0
- package/assets/skills/spike/SKILL.md +535 -0
- package/assets/skills/tdd/SKILL.md +828 -0
- package/bin/cli.js +2 -1
- package/dist/commands/install.d.ts.map +1 -1
- package/dist/commands/install.js +20 -2
- package/dist/commands/install.js.map +1 -1
- package/dist/utils/symlink.d.ts +1 -0
- package/dist/utils/symlink.d.ts.map +1 -1
- package/dist/utils/symlink.js +1 -0
- package/dist/utils/symlink.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,883 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: api-integration
|
|
3
|
+
description: API integration workflow for adding new endpoints or integrating external APIs. Use when adding API endpoints, integrating third-party APIs, or when user says "integrate api", "add endpoint", "new api", "connect api", "api integration".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# API Integration Workflow
|
|
7
|
+
|
|
8
|
+
End-to-end workflow for designing, implementing, testing, and documenting APIs.
|
|
9
|
+
|
|
10
|
+
## IMPORTANT: Read Architecture First
|
|
11
|
+
|
|
12
|
+
**Before starting any phase, you MUST read the appropriate architecture reference:**
|
|
13
|
+
|
|
14
|
+
### Global Architecture Files
|
|
15
|
+
```
|
|
16
|
+
~/.claude/architecture/
|
|
17
|
+
├── clean-architecture.md # Core principles for all projects
|
|
18
|
+
├── flutter-mobile.md # Flutter + Riverpod
|
|
19
|
+
├── react-frontend.md # React + Vite + TypeScript
|
|
20
|
+
├── go-backend.md # Go + Gin
|
|
21
|
+
├── laravel-backend.md # Laravel + PHP
|
|
22
|
+
├── remix-fullstack.md # Remix fullstack
|
|
23
|
+
└── monorepo.md # Monorepo structure
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Project-specific (if exists)
|
|
27
|
+
```
|
|
28
|
+
.claude/architecture/ # Project overrides
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Follow the structure and patterns defined in these files exactly.**
|
|
32
|
+
|
|
33
|
+
## Recommended Agents
|
|
34
|
+
|
|
35
|
+
| Phase | Agent | Purpose |
|
|
36
|
+
|-------|-------|---------|
|
|
37
|
+
| DESIGN | `@api-designer` | API contract design (OpenAPI) |
|
|
38
|
+
| DESIGN | `@clean-architect` | Ensure architecture compliance |
|
|
39
|
+
| IMPLEMENT | `@go-backend-dev`, `@laravel-backend-dev`, `@remix-fullstack-dev` | Backend implementation |
|
|
40
|
+
| IMPLEMENT | `@react-frontend-dev`, `@flutter-mobile-dev` | Client integration |
|
|
41
|
+
| IMPLEMENT | `@db-designer` | Database schema (if needed) |
|
|
42
|
+
| TEST | `@test-writer` | API tests (unit/integration) |
|
|
43
|
+
| TEST | `@security-audit` | Security testing |
|
|
44
|
+
| DOCUMENT | `@docs-writer` | API documentation |
|
|
45
|
+
|
|
46
|
+
## Workflow Overview
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
|
|
50
|
+
│ 1. DESIGN│──▶│2. IMPLEMENT──▶│ 3. TEST │──▶│4. DOCUMENT
|
|
51
|
+
└──────────┘ └──────────┘ └──────────┘ └──────────┘
|
|
52
|
+
│
|
|
53
|
+
└───────────◀──────────┘
|
|
54
|
+
Feedback Loop
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Phase 1: DESIGN
|
|
60
|
+
|
|
61
|
+
**Goal**: Design API contract (request/response, endpoints, schema)
|
|
62
|
+
|
|
63
|
+
### Actions
|
|
64
|
+
1. Identify API type:
|
|
65
|
+
- [ ] REST API
|
|
66
|
+
- [ ] GraphQL API
|
|
67
|
+
- [ ] gRPC
|
|
68
|
+
- [ ] Third-party integration
|
|
69
|
+
|
|
70
|
+
2. **Read architecture doc** for the stack
|
|
71
|
+
3. Define API contract:
|
|
72
|
+
- Endpoints/operations
|
|
73
|
+
- Request/response schema
|
|
74
|
+
- HTTP methods
|
|
75
|
+
- Status codes
|
|
76
|
+
- Authentication/authorization
|
|
77
|
+
- Error handling
|
|
78
|
+
|
|
79
|
+
4. Create OpenAPI spec (REST) or GraphQL schema
|
|
80
|
+
|
|
81
|
+
### Output Template
|
|
82
|
+
```yaml
|
|
83
|
+
# OpenAPI 3.0 Spec Example
|
|
84
|
+
openapi: 3.0.0
|
|
85
|
+
info:
|
|
86
|
+
title: [API Name]
|
|
87
|
+
version: 1.0.0
|
|
88
|
+
description: [API Description]
|
|
89
|
+
|
|
90
|
+
servers:
|
|
91
|
+
- url: https://api.example.com/v1
|
|
92
|
+
|
|
93
|
+
paths:
|
|
94
|
+
/resource:
|
|
95
|
+
get:
|
|
96
|
+
summary: [Description]
|
|
97
|
+
parameters:
|
|
98
|
+
- name: id
|
|
99
|
+
in: query
|
|
100
|
+
schema:
|
|
101
|
+
type: string
|
|
102
|
+
responses:
|
|
103
|
+
'200':
|
|
104
|
+
description: Success
|
|
105
|
+
content:
|
|
106
|
+
application/json:
|
|
107
|
+
schema:
|
|
108
|
+
$ref: '#/components/schemas/Resource'
|
|
109
|
+
'400':
|
|
110
|
+
description: Bad Request
|
|
111
|
+
'401':
|
|
112
|
+
description: Unauthorized
|
|
113
|
+
'404':
|
|
114
|
+
description: Not Found
|
|
115
|
+
'500':
|
|
116
|
+
description: Internal Server Error
|
|
117
|
+
|
|
118
|
+
components:
|
|
119
|
+
schemas:
|
|
120
|
+
Resource:
|
|
121
|
+
type: object
|
|
122
|
+
properties:
|
|
123
|
+
id:
|
|
124
|
+
type: string
|
|
125
|
+
name:
|
|
126
|
+
type: string
|
|
127
|
+
required:
|
|
128
|
+
- id
|
|
129
|
+
- name
|
|
130
|
+
securitySchemes:
|
|
131
|
+
BearerAuth:
|
|
132
|
+
type: http
|
|
133
|
+
scheme: bearer
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Design Checklist
|
|
137
|
+
```markdown
|
|
138
|
+
## API Design: [Endpoint/Feature Name]
|
|
139
|
+
|
|
140
|
+
### Reference
|
|
141
|
+
- Architecture Doc: [path to architecture file]
|
|
142
|
+
- API Type: [REST/GraphQL/gRPC]
|
|
143
|
+
- Stack: [Go/Laravel/Remix/etc.]
|
|
144
|
+
|
|
145
|
+
### Endpoints
|
|
146
|
+
| Method | Path | Description | Auth Required |
|
|
147
|
+
|--------|------|-------------|---------------|
|
|
148
|
+
| GET | /api/resource | List resources | Yes |
|
|
149
|
+
| POST | /api/resource | Create resource | Yes |
|
|
150
|
+
| GET | /api/resource/:id | Get resource | Yes |
|
|
151
|
+
| PUT | /api/resource/:id | Update resource | Yes |
|
|
152
|
+
| DELETE | /api/resource/:id | Delete resource | Yes |
|
|
153
|
+
|
|
154
|
+
### Request/Response Schema
|
|
155
|
+
[Define schemas here]
|
|
156
|
+
|
|
157
|
+
### Authentication
|
|
158
|
+
- Method: [Bearer Token/JWT/API Key/OAuth2]
|
|
159
|
+
- Header: [Authorization: Bearer {token}]
|
|
160
|
+
|
|
161
|
+
### Error Handling
|
|
162
|
+
- 400: Validation errors
|
|
163
|
+
- 401: Authentication failed
|
|
164
|
+
- 403: Authorization failed
|
|
165
|
+
- 404: Resource not found
|
|
166
|
+
- 500: Server error
|
|
167
|
+
|
|
168
|
+
### Rate Limiting
|
|
169
|
+
- Limit: [requests per minute]
|
|
170
|
+
- Headers: X-RateLimit-Limit, X-RateLimit-Remaining
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Gate
|
|
174
|
+
- [ ] Architecture doc read
|
|
175
|
+
- [ ] API type identified
|
|
176
|
+
- [ ] All endpoints defined
|
|
177
|
+
- [ ] Request/response schema defined
|
|
178
|
+
- [ ] Authentication strategy defined
|
|
179
|
+
- [ ] Error handling specified
|
|
180
|
+
- [ ] OpenAPI spec created (if REST)
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Phase 2: IMPLEMENT
|
|
185
|
+
|
|
186
|
+
**Goal**: Implement API following architecture patterns
|
|
187
|
+
|
|
188
|
+
### Actions
|
|
189
|
+
1. **Re-read architecture doc** for implementation patterns
|
|
190
|
+
2. Follow the layer structure from doc:
|
|
191
|
+
- Routes/Controllers layer
|
|
192
|
+
- Use Cases/Services layer
|
|
193
|
+
- Repository/Data layer
|
|
194
|
+
- Models/Entities layer
|
|
195
|
+
|
|
196
|
+
3. Implement based on stack:
|
|
197
|
+
|
|
198
|
+
#### Go (Gin)
|
|
199
|
+
```go
|
|
200
|
+
// Follow go-backend.md structure
|
|
201
|
+
// Routes → Handlers → Use Cases → Repositories
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### Laravel
|
|
205
|
+
```php
|
|
206
|
+
// Follow laravel-backend.md structure
|
|
207
|
+
// Routes → Controllers → Services → Repositories
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### Remix
|
|
211
|
+
```typescript
|
|
212
|
+
// Follow remix-fullstack.md structure
|
|
213
|
+
// Routes → Actions/Loaders → Services → Repositories
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
4. Implement validation:
|
|
217
|
+
- Request validation
|
|
218
|
+
- Schema validation
|
|
219
|
+
- Business rules validation
|
|
220
|
+
|
|
221
|
+
5. Implement error handling per architecture doc
|
|
222
|
+
|
|
223
|
+
6. Implement authentication/authorization
|
|
224
|
+
|
|
225
|
+
### Implementation Checklist
|
|
226
|
+
```markdown
|
|
227
|
+
## Implementation: [API Name]
|
|
228
|
+
|
|
229
|
+
### Architecture Reference
|
|
230
|
+
- Doc: [architecture file path]
|
|
231
|
+
- Pattern: [pattern from doc]
|
|
232
|
+
|
|
233
|
+
### Layer Implementation (from architecture doc)
|
|
234
|
+
- [ ] Routes/API layer
|
|
235
|
+
- [ ] Controller/Handler layer
|
|
236
|
+
- [ ] Use Case/Service layer
|
|
237
|
+
- [ ] Repository/Data layer
|
|
238
|
+
- [ ] Models/DTOs
|
|
239
|
+
|
|
240
|
+
### Validation
|
|
241
|
+
- [ ] Request validation
|
|
242
|
+
- [ ] Schema validation
|
|
243
|
+
- [ ] Business rules
|
|
244
|
+
|
|
245
|
+
### Security
|
|
246
|
+
- [ ] Authentication implemented
|
|
247
|
+
- [ ] Authorization implemented
|
|
248
|
+
- [ ] Input sanitization
|
|
249
|
+
- [ ] SQL injection prevention
|
|
250
|
+
- [ ] XSS prevention
|
|
251
|
+
|
|
252
|
+
### Error Handling
|
|
253
|
+
- [ ] Custom error types
|
|
254
|
+
- [ ] Error middleware
|
|
255
|
+
- [ ] Consistent error format
|
|
256
|
+
- [ ] Logging
|
|
257
|
+
|
|
258
|
+
### Testing Endpoints
|
|
259
|
+
# GET
|
|
260
|
+
curl -X GET http://localhost:8080/api/resource \
|
|
261
|
+
-H "Authorization: Bearer {token}"
|
|
262
|
+
|
|
263
|
+
# POST
|
|
264
|
+
curl -X POST http://localhost:8080/api/resource \
|
|
265
|
+
-H "Authorization: Bearer {token}" \
|
|
266
|
+
-H "Content-Type: application/json" \
|
|
267
|
+
-d '{"name": "test"}'
|
|
268
|
+
|
|
269
|
+
# PUT
|
|
270
|
+
curl -X PUT http://localhost:8080/api/resource/123 \
|
|
271
|
+
-H "Authorization: Bearer {token}" \
|
|
272
|
+
-H "Content-Type: application/json" \
|
|
273
|
+
-d '{"name": "updated"}'
|
|
274
|
+
|
|
275
|
+
# DELETE
|
|
276
|
+
curl -X DELETE http://localhost:8080/api/resource/123 \
|
|
277
|
+
-H "Authorization: Bearer {token}"
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Gate
|
|
281
|
+
- [ ] Follows architecture doc structure
|
|
282
|
+
- [ ] All layers implemented
|
|
283
|
+
- [ ] Validation works
|
|
284
|
+
- [ ] Authentication/authorization works
|
|
285
|
+
- [ ] Error handling works
|
|
286
|
+
- [ ] Manual testing successful
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Phase 3: TEST
|
|
291
|
+
|
|
292
|
+
**Goal**: Write comprehensive API tests
|
|
293
|
+
|
|
294
|
+
### Actions
|
|
295
|
+
1. **Read testing patterns from architecture doc**
|
|
296
|
+
2. Write tests following doc conventions:
|
|
297
|
+
- Unit tests for each layer
|
|
298
|
+
- Integration tests for endpoints
|
|
299
|
+
- E2E tests for workflows
|
|
300
|
+
|
|
301
|
+
3. Test coverage:
|
|
302
|
+
- [ ] Happy path
|
|
303
|
+
- [ ] Validation errors (400)
|
|
304
|
+
- [ ] Authentication errors (401)
|
|
305
|
+
- [ ] Authorization errors (403)
|
|
306
|
+
- [ ] Not found errors (404)
|
|
307
|
+
- [ ] Server errors (500)
|
|
308
|
+
- [ ] Edge cases
|
|
309
|
+
- [ ] Rate limiting (if applicable)
|
|
310
|
+
|
|
311
|
+
4. Security testing:
|
|
312
|
+
- [ ] SQL injection attempts
|
|
313
|
+
- [ ] XSS attempts
|
|
314
|
+
- [ ] Invalid tokens
|
|
315
|
+
- [ ] Expired tokens
|
|
316
|
+
- [ ] CSRF protection (if applicable)
|
|
317
|
+
|
|
318
|
+
### Test Template
|
|
319
|
+
|
|
320
|
+
#### Go Example
|
|
321
|
+
```go
|
|
322
|
+
func TestGetResource(t *testing.T) {
|
|
323
|
+
// Setup
|
|
324
|
+
router := setupTestRouter()
|
|
325
|
+
|
|
326
|
+
// Test cases
|
|
327
|
+
tests := []struct {
|
|
328
|
+
name string
|
|
329
|
+
resourceID string
|
|
330
|
+
token string
|
|
331
|
+
expectedStatus int
|
|
332
|
+
expectedBody string
|
|
333
|
+
}{
|
|
334
|
+
{
|
|
335
|
+
name: "Success",
|
|
336
|
+
resourceID: "123",
|
|
337
|
+
token: validToken,
|
|
338
|
+
expectedStatus: 200,
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
name: "Unauthorized",
|
|
342
|
+
resourceID: "123",
|
|
343
|
+
token: "",
|
|
344
|
+
expectedStatus: 401,
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: "Not Found",
|
|
348
|
+
resourceID: "999",
|
|
349
|
+
token: validToken,
|
|
350
|
+
expectedStatus: 404,
|
|
351
|
+
},
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
for _, tt := range tests {
|
|
355
|
+
t.Run(tt.name, func(t *testing.T) {
|
|
356
|
+
req := httptest.NewRequest("GET", "/api/resource/"+tt.resourceID, nil)
|
|
357
|
+
if tt.token != "" {
|
|
358
|
+
req.Header.Set("Authorization", "Bearer "+tt.token)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
w := httptest.NewRecorder()
|
|
362
|
+
router.ServeHTTP(w, req)
|
|
363
|
+
|
|
364
|
+
assert.Equal(t, tt.expectedStatus, w.Code)
|
|
365
|
+
})
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
#### Laravel Example
|
|
371
|
+
```php
|
|
372
|
+
public function test_get_resource()
|
|
373
|
+
{
|
|
374
|
+
// Happy path
|
|
375
|
+
$response = $this->withHeaders([
|
|
376
|
+
'Authorization' => 'Bearer ' . $this->token,
|
|
377
|
+
])->get('/api/resource/123');
|
|
378
|
+
|
|
379
|
+
$response->assertStatus(200)
|
|
380
|
+
->assertJson(['id' => '123']);
|
|
381
|
+
|
|
382
|
+
// Unauthorized
|
|
383
|
+
$response = $this->get('/api/resource/123');
|
|
384
|
+
$response->assertStatus(401);
|
|
385
|
+
|
|
386
|
+
// Not found
|
|
387
|
+
$response = $this->withHeaders([
|
|
388
|
+
'Authorization' => 'Bearer ' . $this->token,
|
|
389
|
+
])->get('/api/resource/999');
|
|
390
|
+
|
|
391
|
+
$response->assertStatus(404);
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
#### TypeScript/Remix Example
|
|
396
|
+
```typescript
|
|
397
|
+
describe('GET /api/resource', () => {
|
|
398
|
+
it('should return resource with valid auth', async () => {
|
|
399
|
+
const response = await fetch('/api/resource/123', {
|
|
400
|
+
headers: {
|
|
401
|
+
'Authorization': `Bearer ${validToken}`,
|
|
402
|
+
},
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
expect(response.status).toBe(200);
|
|
406
|
+
const data = await response.json();
|
|
407
|
+
expect(data.id).toBe('123');
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it('should return 401 without auth', async () => {
|
|
411
|
+
const response = await fetch('/api/resource/123');
|
|
412
|
+
expect(response.status).toBe(401);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('should return 404 for non-existent resource', async () => {
|
|
416
|
+
const response = await fetch('/api/resource/999', {
|
|
417
|
+
headers: {
|
|
418
|
+
'Authorization': `Bearer ${validToken}`,
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
expect(response.status).toBe(404);
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### Run Tests
|
|
428
|
+
```bash
|
|
429
|
+
# Go
|
|
430
|
+
go test ./... -v -cover
|
|
431
|
+
|
|
432
|
+
# Laravel
|
|
433
|
+
php artisan test --coverage
|
|
434
|
+
|
|
435
|
+
# React/Remix
|
|
436
|
+
bun test --coverage
|
|
437
|
+
|
|
438
|
+
# Flutter (client integration)
|
|
439
|
+
flutter test
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### Gate
|
|
443
|
+
- [ ] Unit tests pass
|
|
444
|
+
- [ ] Integration tests pass
|
|
445
|
+
- [ ] All status codes tested
|
|
446
|
+
- [ ] Security tests pass
|
|
447
|
+
- [ ] Edge cases covered
|
|
448
|
+
- [ ] Coverage meets standards (>80%)
|
|
449
|
+
|
|
450
|
+
### Feedback Loop
|
|
451
|
+
If tests fail → Return to IMPLEMENT → Fix → Re-test
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
## Phase 4: DOCUMENT
|
|
456
|
+
|
|
457
|
+
**Goal**: Create clear, accurate API documentation
|
|
458
|
+
|
|
459
|
+
### Actions
|
|
460
|
+
1. Generate documentation from OpenAPI spec (if REST)
|
|
461
|
+
2. Write usage examples
|
|
462
|
+
3. Document authentication flow
|
|
463
|
+
4. Document error codes
|
|
464
|
+
5. Create Postman/Insomnia collection (optional)
|
|
465
|
+
|
|
466
|
+
### Documentation Template
|
|
467
|
+
```markdown
|
|
468
|
+
# [API Name] Documentation
|
|
469
|
+
|
|
470
|
+
## Base URL
|
|
471
|
+
```
|
|
472
|
+
https://api.example.com/v1
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
## Authentication
|
|
476
|
+
|
|
477
|
+
All endpoints require authentication unless specified otherwise.
|
|
478
|
+
|
|
479
|
+
### Bearer Token
|
|
480
|
+
```bash
|
|
481
|
+
Authorization: Bearer {your_token}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### Getting a Token
|
|
485
|
+
```bash
|
|
486
|
+
POST /auth/login
|
|
487
|
+
Content-Type: application/json
|
|
488
|
+
|
|
489
|
+
{
|
|
490
|
+
"email": "user@example.com",
|
|
491
|
+
"password": "password"
|
|
492
|
+
}
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
Response:
|
|
496
|
+
```json
|
|
497
|
+
{
|
|
498
|
+
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
499
|
+
"expires_in": 3600
|
|
500
|
+
}
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
## Endpoints
|
|
504
|
+
|
|
505
|
+
### List Resources
|
|
506
|
+
```http
|
|
507
|
+
GET /api/resource
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
**Query Parameters**
|
|
511
|
+
| Parameter | Type | Required | Description |
|
|
512
|
+
|-----------|------|----------|-------------|
|
|
513
|
+
| page | integer | No | Page number (default: 1) |
|
|
514
|
+
| limit | integer | No | Items per page (default: 10, max: 100) |
|
|
515
|
+
| sort | string | No | Sort field (default: created_at) |
|
|
516
|
+
| order | string | No | Sort order: asc/desc (default: desc) |
|
|
517
|
+
|
|
518
|
+
**Response 200 OK**
|
|
519
|
+
```json
|
|
520
|
+
{
|
|
521
|
+
"data": [
|
|
522
|
+
{
|
|
523
|
+
"id": "123",
|
|
524
|
+
"name": "Resource Name",
|
|
525
|
+
"created_at": "2026-02-02T10:00:00Z",
|
|
526
|
+
"updated_at": "2026-02-02T10:00:00Z"
|
|
527
|
+
}
|
|
528
|
+
],
|
|
529
|
+
"meta": {
|
|
530
|
+
"page": 1,
|
|
531
|
+
"limit": 10,
|
|
532
|
+
"total": 100,
|
|
533
|
+
"total_pages": 10
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
**Example**
|
|
539
|
+
```bash
|
|
540
|
+
curl -X GET "https://api.example.com/v1/api/resource?page=1&limit=10" \
|
|
541
|
+
-H "Authorization: Bearer {token}"
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
### Create Resource
|
|
545
|
+
```http
|
|
546
|
+
POST /api/resource
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
**Request Body**
|
|
550
|
+
```json
|
|
551
|
+
{
|
|
552
|
+
"name": "New Resource",
|
|
553
|
+
"description": "Description"
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
**Response 201 Created**
|
|
558
|
+
```json
|
|
559
|
+
{
|
|
560
|
+
"id": "124",
|
|
561
|
+
"name": "New Resource",
|
|
562
|
+
"description": "Description",
|
|
563
|
+
"created_at": "2026-02-02T10:00:00Z",
|
|
564
|
+
"updated_at": "2026-02-02T10:00:00Z"
|
|
565
|
+
}
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
**Example**
|
|
569
|
+
```bash
|
|
570
|
+
curl -X POST "https://api.example.com/v1/api/resource" \
|
|
571
|
+
-H "Authorization: Bearer {token}" \
|
|
572
|
+
-H "Content-Type: application/json" \
|
|
573
|
+
-d '{
|
|
574
|
+
"name": "New Resource",
|
|
575
|
+
"description": "Description"
|
|
576
|
+
}'
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
### Get Resource
|
|
580
|
+
```http
|
|
581
|
+
GET /api/resource/:id
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
**Path Parameters**
|
|
585
|
+
| Parameter | Type | Required | Description |
|
|
586
|
+
|-----------|------|----------|-------------|
|
|
587
|
+
| id | string | Yes | Resource ID |
|
|
588
|
+
|
|
589
|
+
**Response 200 OK**
|
|
590
|
+
```json
|
|
591
|
+
{
|
|
592
|
+
"id": "123",
|
|
593
|
+
"name": "Resource Name",
|
|
594
|
+
"description": "Description",
|
|
595
|
+
"created_at": "2026-02-02T10:00:00Z",
|
|
596
|
+
"updated_at": "2026-02-02T10:00:00Z"
|
|
597
|
+
}
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
**Example**
|
|
601
|
+
```bash
|
|
602
|
+
curl -X GET "https://api.example.com/v1/api/resource/123" \
|
|
603
|
+
-H "Authorization: Bearer {token}"
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
### Update Resource
|
|
607
|
+
```http
|
|
608
|
+
PUT /api/resource/:id
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
**Path Parameters**
|
|
612
|
+
| Parameter | Type | Required | Description |
|
|
613
|
+
|-----------|------|----------|-------------|
|
|
614
|
+
| id | string | Yes | Resource ID |
|
|
615
|
+
|
|
616
|
+
**Request Body**
|
|
617
|
+
```json
|
|
618
|
+
{
|
|
619
|
+
"name": "Updated Name",
|
|
620
|
+
"description": "Updated Description"
|
|
621
|
+
}
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
**Response 200 OK**
|
|
625
|
+
```json
|
|
626
|
+
{
|
|
627
|
+
"id": "123",
|
|
628
|
+
"name": "Updated Name",
|
|
629
|
+
"description": "Updated Description",
|
|
630
|
+
"created_at": "2026-02-02T10:00:00Z",
|
|
631
|
+
"updated_at": "2026-02-02T11:00:00Z"
|
|
632
|
+
}
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
**Example**
|
|
636
|
+
```bash
|
|
637
|
+
curl -X PUT "https://api.example.com/v1/api/resource/123" \
|
|
638
|
+
-H "Authorization: Bearer {token}" \
|
|
639
|
+
-H "Content-Type: application/json" \
|
|
640
|
+
-d '{
|
|
641
|
+
"name": "Updated Name",
|
|
642
|
+
"description": "Updated Description"
|
|
643
|
+
}'
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
### Delete Resource
|
|
647
|
+
```http
|
|
648
|
+
DELETE /api/resource/:id
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
**Path Parameters**
|
|
652
|
+
| Parameter | Type | Required | Description |
|
|
653
|
+
|-----------|------|----------|-------------|
|
|
654
|
+
| id | string | Yes | Resource ID |
|
|
655
|
+
|
|
656
|
+
**Response 204 No Content**
|
|
657
|
+
|
|
658
|
+
**Example**
|
|
659
|
+
```bash
|
|
660
|
+
curl -X DELETE "https://api.example.com/v1/api/resource/123" \
|
|
661
|
+
-H "Authorization: Bearer {token}"
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
## Error Codes
|
|
665
|
+
|
|
666
|
+
| Code | Description | Example |
|
|
667
|
+
|------|-------------|---------|
|
|
668
|
+
| 400 | Bad Request - Validation failed | Missing required field |
|
|
669
|
+
| 401 | Unauthorized - Invalid or missing token | Token expired |
|
|
670
|
+
| 403 | Forbidden - Insufficient permissions | User role not allowed |
|
|
671
|
+
| 404 | Not Found - Resource doesn't exist | Invalid resource ID |
|
|
672
|
+
| 422 | Unprocessable Entity - Business logic error | Duplicate entry |
|
|
673
|
+
| 429 | Too Many Requests - Rate limit exceeded | Exceeded 100 req/min |
|
|
674
|
+
| 500 | Internal Server Error - Server issue | Database connection failed |
|
|
675
|
+
|
|
676
|
+
### Error Response Format
|
|
677
|
+
```json
|
|
678
|
+
{
|
|
679
|
+
"error": {
|
|
680
|
+
"code": "VALIDATION_ERROR",
|
|
681
|
+
"message": "Validation failed",
|
|
682
|
+
"details": [
|
|
683
|
+
{
|
|
684
|
+
"field": "name",
|
|
685
|
+
"message": "Name is required"
|
|
686
|
+
}
|
|
687
|
+
]
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
## Rate Limiting
|
|
693
|
+
|
|
694
|
+
- **Limit**: 100 requests per minute per API key
|
|
695
|
+
- **Headers**:
|
|
696
|
+
- `X-RateLimit-Limit`: Maximum requests allowed
|
|
697
|
+
- `X-RateLimit-Remaining`: Remaining requests
|
|
698
|
+
- `X-RateLimit-Reset`: Unix timestamp when limit resets
|
|
699
|
+
|
|
700
|
+
When rate limit is exceeded, you'll receive a 429 response:
|
|
701
|
+
```json
|
|
702
|
+
{
|
|
703
|
+
"error": {
|
|
704
|
+
"code": "RATE_LIMIT_EXCEEDED",
|
|
705
|
+
"message": "Too many requests. Please try again later.",
|
|
706
|
+
"retry_after": 60
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
## Pagination
|
|
712
|
+
|
|
713
|
+
All list endpoints support pagination:
|
|
714
|
+
|
|
715
|
+
**Query Parameters**
|
|
716
|
+
- `page`: Page number (default: 1)
|
|
717
|
+
- `limit`: Items per page (default: 10, max: 100)
|
|
718
|
+
|
|
719
|
+
**Response Meta**
|
|
720
|
+
```json
|
|
721
|
+
{
|
|
722
|
+
"data": [...],
|
|
723
|
+
"meta": {
|
|
724
|
+
"page": 1,
|
|
725
|
+
"limit": 10,
|
|
726
|
+
"total": 100,
|
|
727
|
+
"total_pages": 10
|
|
728
|
+
},
|
|
729
|
+
"links": {
|
|
730
|
+
"first": "/api/resource?page=1",
|
|
731
|
+
"prev": null,
|
|
732
|
+
"next": "/api/resource?page=2",
|
|
733
|
+
"last": "/api/resource?page=10"
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
## Versioning
|
|
739
|
+
|
|
740
|
+
API versioning is handled via the URL path:
|
|
741
|
+
- Current: `/v1/`
|
|
742
|
+
- Legacy: `/v1/` (deprecated)
|
|
743
|
+
|
|
744
|
+
Breaking changes will result in a new version.
|
|
745
|
+
|
|
746
|
+
## SDKs and Tools
|
|
747
|
+
|
|
748
|
+
### Postman Collection
|
|
749
|
+
[Download Postman Collection](./postman_collection.json)
|
|
750
|
+
|
|
751
|
+
### Code Examples
|
|
752
|
+
|
|
753
|
+
#### JavaScript/TypeScript
|
|
754
|
+
```typescript
|
|
755
|
+
const response = await fetch('https://api.example.com/v1/api/resource', {
|
|
756
|
+
method: 'GET',
|
|
757
|
+
headers: {
|
|
758
|
+
'Authorization': `Bearer ${token}`,
|
|
759
|
+
'Content-Type': 'application/json',
|
|
760
|
+
},
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
const data = await response.json();
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
#### Python
|
|
767
|
+
```python
|
|
768
|
+
import requests
|
|
769
|
+
|
|
770
|
+
headers = {
|
|
771
|
+
'Authorization': f'Bearer {token}',
|
|
772
|
+
'Content-Type': 'application/json',
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
response = requests.get(
|
|
776
|
+
'https://api.example.com/v1/api/resource',
|
|
777
|
+
headers=headers
|
|
778
|
+
)
|
|
779
|
+
data = response.json()
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
#### Go
|
|
783
|
+
```go
|
|
784
|
+
req, _ := http.NewRequest("GET", "https://api.example.com/v1/api/resource", nil)
|
|
785
|
+
req.Header.Set("Authorization", "Bearer "+token)
|
|
786
|
+
req.Header.Set("Content-Type", "application/json")
|
|
787
|
+
|
|
788
|
+
client := &http.Client{}
|
|
789
|
+
resp, _ := client.Do(req)
|
|
790
|
+
defer resp.Body.Close()
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
## Support
|
|
794
|
+
|
|
795
|
+
For API support, contact: api-support@example.com
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
### Documentation Checklist
|
|
799
|
+
- [ ] All endpoints documented
|
|
800
|
+
- [ ] Request/response examples provided
|
|
801
|
+
- [ ] Authentication documented
|
|
802
|
+
- [ ] Error codes documented
|
|
803
|
+
- [ ] Rate limiting documented
|
|
804
|
+
- [ ] Code examples provided
|
|
805
|
+
- [ ] Postman collection created (optional)
|
|
806
|
+
|
|
807
|
+
### Gate
|
|
808
|
+
- [ ] Documentation complete
|
|
809
|
+
- [ ] Examples tested
|
|
810
|
+
- [ ] OpenAPI spec updated
|
|
811
|
+
- [ ] README updated (if needed)
|
|
812
|
+
|
|
813
|
+
---
|
|
814
|
+
|
|
815
|
+
## Quick Reference
|
|
816
|
+
|
|
817
|
+
### HTTP Status Codes
|
|
818
|
+
| Code | Meaning | Use Case |
|
|
819
|
+
|------|---------|----------|
|
|
820
|
+
| 200 | OK | Successful GET, PUT, PATCH |
|
|
821
|
+
| 201 | Created | Successful POST |
|
|
822
|
+
| 204 | No Content | Successful DELETE |
|
|
823
|
+
| 400 | Bad Request | Validation error |
|
|
824
|
+
| 401 | Unauthorized | Missing/invalid auth |
|
|
825
|
+
| 403 | Forbidden | Insufficient permissions |
|
|
826
|
+
| 404 | Not Found | Resource not found |
|
|
827
|
+
| 422 | Unprocessable Entity | Business logic error |
|
|
828
|
+
| 429 | Too Many Requests | Rate limit exceeded |
|
|
829
|
+
| 500 | Internal Server Error | Server error |
|
|
830
|
+
|
|
831
|
+
### REST Conventions
|
|
832
|
+
| Method | Path | Action | Success Code |
|
|
833
|
+
|--------|------|--------|--------------|
|
|
834
|
+
| GET | /resource | List all | 200 |
|
|
835
|
+
| GET | /resource/:id | Get one | 200 |
|
|
836
|
+
| POST | /resource | Create | 201 |
|
|
837
|
+
| PUT | /resource/:id | Update (full) | 200 |
|
|
838
|
+
| PATCH | /resource/:id | Update (partial) | 200 |
|
|
839
|
+
| DELETE | /resource/:id | Delete | 204 |
|
|
840
|
+
|
|
841
|
+
### API Design Best Practices
|
|
842
|
+
1. **Use nouns for resources**, not verbs (e.g., `/users` not `/getUsers`)
|
|
843
|
+
2. **Use HTTP methods** for actions (GET, POST, PUT, DELETE)
|
|
844
|
+
3. **Version your API** (`/v1/resource`)
|
|
845
|
+
4. **Use plural nouns** (`/users` not `/user`)
|
|
846
|
+
5. **Use query params for filtering/sorting** (`?status=active&sort=name`)
|
|
847
|
+
6. **Return consistent error format**
|
|
848
|
+
7. **Use proper status codes**
|
|
849
|
+
8. **Implement pagination** for list endpoints
|
|
850
|
+
9. **Use authentication** (Bearer tokens, API keys)
|
|
851
|
+
10. **Document everything** (OpenAPI/Swagger)
|
|
852
|
+
|
|
853
|
+
### Authentication Patterns
|
|
854
|
+
| Pattern | Use Case | Implementation |
|
|
855
|
+
|---------|----------|----------------|
|
|
856
|
+
| Bearer Token | Most APIs | `Authorization: Bearer {token}` |
|
|
857
|
+
| API Key | Simple APIs | `X-API-Key: {key}` |
|
|
858
|
+
| JWT | Stateless auth | Decode and verify token |
|
|
859
|
+
| OAuth2 | Third-party integration | OAuth2 flow |
|
|
860
|
+
| Basic Auth | Simple/legacy | `Authorization: Basic {base64}` |
|
|
861
|
+
|
|
862
|
+
### Phase Summary
|
|
863
|
+
| Phase | Key Actions | Output |
|
|
864
|
+
|-------|-------------|--------|
|
|
865
|
+
| DESIGN | Define contract, OpenAPI spec | API specification |
|
|
866
|
+
| IMPLEMENT | Code per architecture doc | Working endpoints |
|
|
867
|
+
| TEST | Unit/integration/security tests | Test coverage >80% |
|
|
868
|
+
| DOCUMENT | API docs, examples, Postman | Complete documentation |
|
|
869
|
+
|
|
870
|
+
### When to Loop Back
|
|
871
|
+
- **TEST fails** → Return to IMPLEMENT
|
|
872
|
+
- **Security issues found** → Return to IMPLEMENT
|
|
873
|
+
- **Design changes** → Return to DESIGN
|
|
874
|
+
|
|
875
|
+
### Success Criteria
|
|
876
|
+
API integration is complete when:
|
|
877
|
+
1. OpenAPI spec created
|
|
878
|
+
2. Follows architecture doc
|
|
879
|
+
3. All endpoints working
|
|
880
|
+
4. Tests passing (>80% coverage)
|
|
881
|
+
5. Security validated
|
|
882
|
+
6. Documentation complete
|
|
883
|
+
7. Ready for production
|