Aşağıdaki uygulama için API tasarla:
UYGULAMA:
- Domain: [E-TİCARET / SaaS / FİNTECH / SAĞLIK / EĞİTİM / DİĞER]
- Tüketici: [WEB / MOBİL / 3. PARTİ / HEPSİ]
- Auth: [API KEY / JWT / OAuth2 / DİĞER]
ÜRET:
1. API TASARIM İLKELERİ:
- RESTful: kaynak odaklı URL (/users, /orders/{id})
- HTTP metotları: GET (oku), POST (oluştur), PUT (güncelle), PATCH (kısmi), DELETE (sil)
- Durum kodları: 200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Conflict, 422 Unprocessable, 429 Too Many, 500 Internal
- Versioning: /api/v1/, header (Accept-Version), query (?v=1)
2. ENDPOINT TASARIMI:
Örnek: E-ticaret
```
GET /api/v1/products # Liste (pagination, filter, sort)
GET /api/v1/products/{id} # Tekil
POST /api/v1/products # Oluştur
PUT /api/v1/products/{id} # Güncelle
DELETE /api/v1/products/{id} # Sil
GET /api/v1/products/{id}/reviews # Alt kaynak
POST /api/v1/orders # Sipariş oluştur
GET /api/v1/users/me # Mevcut kullanıcı
```
3. PAGINATION / FİLTER / SORT:
```
GET /products?page=2&limit=20&sort=-created_at&category=electronics&min_price=100
```
Response: {data: [...], meta: {total, page, limit, pages}}
4. AUTH & GÜVENLİK:
- JWT: access token (15dk) + refresh token (7gün)
- OAuth2: authorization code flow (3. parti)
- Rate limiting: 100 req/dk (429 Too Many Requests), X-RateLimit-* headers
- CORS: allowed origins
- Input validation: type, length, format
- SQL injection / XSS koruması
5. ERROR FORMAT:
```json
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Geçersiz e-posta formatı",
"details": [{"field": "email", "issue": "invalid_format"}]
}
}
```
6. DOKÜMANTASYON:
- OpenAPI 3.0 (Swagger) spec YAML
- Swagger UI (interaktif test)
- Postman collection
- SDK (otomatik üretim: openapi-generator)
- Changelog (versiyonlar arası değişiklik)
7. PERFORMANS:
- Response compression (gzip)
- ETags (conditional GET)
- Field selection (?fields=id,name,price)
- Batch endpoint (toplu işlem)
Türkçe, REST API design best practice.