AgentSkillsCN

api-design

RESTful API 设计标准。在进行 API 设计或端点开发时,自动应用这些标准。

SKILL.md
--- frontmatter
name: api-design
description: "RESTful API tasarım standartları. API TASARIMI veya ENDPOINT GELİŞTİRME yaparken otomatik uygula."
allowed-tools:
  - Read
  - Grep
  - Glob
  - Edit
  - Write

API Design Standards

URL Yapısı

KuralDoğruYanlış
Çoğul isim/users/user
Kebab-case/user-profiles/userProfiles
Lowercase/orders/Orders
İsim kullan/users/getUsers

Resource Hierarchy

code
GET    /users                  # Liste
POST   /users                  # Oluştur
GET    /users/{id}             # Tekil
PUT    /users/{id}             # Güncelle (tam)
PATCH  /users/{id}             # Güncelle (kısmi)
DELETE /users/{id}             # Sil

# Nested
GET    /users/{id}/orders      # User'ın order'ları

HTTP Methods

MethodKullanımIdempotent
GETOku
POSTOluştur
PUTTam güncelle
PATCHKısmi güncelle
DELETESil

Status Codes

Success

CodeKullanım
200GET/PUT/PATCH başarılı
201POST created
204DELETE no content

Client Error

CodeKullanım
400Validation error
401Auth gerekli
403Yetkisiz
404Bulunamadı
409Conflict
429Rate limit

Server Error

CodeKullanım
500Internal error

Response Format

Success

json
{
  "success": true,
  "data": { "id": "usr_123", "email": "..." },
  "meta": { "page": 1, "total": 100 }
}

Error

json
{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Validation failed",
    "details": [{ "field": "email", "message": "Invalid" }]
  }
}

Pagination

code
GET /users?page=2&limit=20
json
{
  "data": [...],
  "meta": {
    "page": 2,
    "limit": 20,
    "total": 150,
    "totalPages": 8
  }
}

Filtering & Sorting

code
GET /users?status=active
GET /users?role=admin&status=active
GET /users?sort=-createdAt       # DESC
GET /users?sort=name             # ASC
GET /users?search=john

Auth Endpoints

code
POST /auth/register
POST /auth/login        → token döner
POST /auth/logout
POST /auth/refresh
GET  /auth/me

Headers

code
Content-Type: application/json
Authorization: Bearer <token>
Accept: application/json