Not: En güncel API referansı için projeyi çalıştırıp
http://localhost:8000/docsüzerinden Swagger UI'a bakınız. Bu döküman özet ve örnekler içerir.
# Projeyi çalıştır
make run # ya da: uvicorn app.main:app --reload
# Sonra tarayıcıdan:
# API: http://localhost:8000
# Swagger: http://localhost:8000/docs
# Dashboard: http://localhost:8000/dashboardTüm API endpoint'leri (GET dahil) Authorization: Bearer <token> header'ı ister. Token, /api/auth/login akışından elde edilir. Uygulama bcrypt parola hash + HS256 imzalı JWT kullanır.
Tek istisna — legacy
X-API-Key: Yalnız/api/model-performancealtındaki 2 route eskiX-API-Keyheader'ını kabul eder. Bunun dışındaki hiçbir endpoint X-API-Key ile çalışmaz; her zaman Bearer JWT kullanın.
| Ortam | API Key (yalnız /api/model-performance legacy) |
|---|---|
| Development (varsayılan) | dev-api-key |
| Production | .env dosyasındaki API_KEY (ENVIRONMENT=production iken default değer reddedilir) |
| Method | Endpoint | Açıklama |
|---|---|---|
| POST | /api/auth/register |
Email + parola → user kaydı (bcrypt hash) |
| POST | /api/auth/login |
Email + parola → {access_token} döner (HS256 JWT) |
| GET | /api/auth/me |
Bearer token ile mevcut kullanıcıyı döner |
| POST | /api/auth/logout |
Token'ı in-memory blacklist'e atar |
# Register
curl -X POST http://localhost:8000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"email":"farmer@example.com","password":"s3cret123","full_name":"Çiftçi Ahmet"}'
# Login → token al
TOKEN=$(curl -s -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"farmer@example.com","password":"s3cret123"}' | jq -r .access_token)
# Korumalı endpoint (her endpoint Bearer ister)
curl http://localhost:8000/api/auth/me -H "Authorization: Bearer $TOKEN"Demo hesaplar: Seed verisindeki 6 demo hesabın hepsinin parolası
123456'dır. Örn. login için herhangi bir demo email +123456kullanın.
Not: Logout sırasında token in-memory blacklist'e eklenir; production'da bu blacklist Redis veya DB'ye taşınmalı.
http://localhost:8000/docs- Önce
POST /api/auth/loginile token al (demo email +123456) - Sağ üstteki 🔒 Authorize butonuna tıkla
bearerAuthalanına token'ı yapıştır, Authorize → Close- Artık 🔒 simgeli endpoint'leri test edebilirsin
curl -X POST http://localhost:8000/api/sensors/ \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"field_id": 1, "sensor_type": "soil_moisture", "serial_number": "S-001"}'| Kategori | Prefix | Örnek endpoint |
|---|---|---|
| Health | /api/health |
GET /api/health, GET /api/health/deep |
| Auth (skeleton) | /api/auth |
POST /api/auth/register, POST /api/auth/login, GET /api/auth/me (Bearer) |
| Sensörler | /api/sensors |
GET /api/sensors/, POST /api/sensors/ (auth) |
| Hava Durumu | /api/weather |
GET /api/weather/, GET /api/weather/latest/{farm_id} |
| Sulama (ML) | /api/irrigation |
POST /api/irrigation/predict |
| Gübreleme | /api/fertilizer |
GET /api/fertilizer/crops (17 bitki), POST /api/fertilizer/recommend |
| Bitki Sağlığı | /api/plants |
GET /api/plants/health-images |
| Analitik | /api/analytics |
GET /api/analytics/summary?days=30, GET /api/analytics/export?format=pdf|xlsx |
| Sistem Uyarıları | /api/alerts |
GET /api/alerts/, POST /api/alerts/ (auth) |
| Model Performansı | /api/model-performance |
GET /api/model-performance/summary/{model_name} |
Tam liste ve her endpoint'in detaylı parametreleri Swagger'da.
curl -X POST http://localhost:8000/api/irrigation/predict \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"soil_moisture": 30,
"soil_temperature": 22,
"humidity": 60,
"temperature": 25,
"precipitation": 2
}'Yanıt:
{
"recommended_water_liters": 28.37,
"irrigation_needed": true,
"confidence": 0.8,
"message": "Orta duzeyde sulama gerekli: 28.37 litre."
}curl -X POST http://localhost:8000/api/fertilizer/recommend \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"crop_type": "tomato",
"area_hectares": 1.0,
"soil_nitrogen": 80,
"soil_phosphorus": 40,
"soil_potassium": 50,
"soil_ph": 6.5
}'
crop_typedeğerleri:wheat,corn,barley,rice,tomato,pepper,potato,cotton,sunflower,sugar_beet,olive,grape,apple,citrus,hazelnut,pistachio,tea(17 bitki).
curl "http://localhost:8000/api/sensors/1/readings?limit=10" \
-H "Authorization: Bearer $TOKEN"curl "http://localhost:8000/api/analytics/summary?days=30" \
-H "Authorization: Bearer $TOKEN" | jq .countscurl "http://localhost:8000/api/analytics/export?format=pdf&days=30" \
-H "Authorization: Bearer $TOKEN" -o rapor.pdfcurl "http://localhost:8000/api/analytics/compare?\
start_date_1=2026-04-01&end_date_1=2026-04-15&\
start_date_2=2026-04-16&end_date_2=2026-04-30" \
-H "Authorization: Bearer $TOKEN"curl -X POST http://localhost:8000/api/alerts/ \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"farm_id": 1,
"alert_type": "sensor_anomaly",
"severity": "medium",
"message": "Sensör 5 son 2 saatte veri göndermedi"
}'curl http://localhost:8000/api/health/deep \
-H "Authorization: Bearer $TOKEN" | jqDB, scheduler ve ML model bileşenlerinin durumunu döner.
| Kod | Anlam | Çözüm |
|---|---|---|
| 401 | Bearer token eksik veya geçersiz | /api/auth/login ile token al, Authorization: Bearer <token> header'ı ekle |
| 403 | Yetki yetersiz (rol/erişim) | Hesabın rolünü/erişimini doğrula |
| 404 | Kayıt bulunamadı | ID'yi doğrula |
| 422 | Validation hatası | Body/query parametrelerini kontrol et |
| 429 | Rate limit aşıldı | Birkaç saniye bekle |
| 500 | Sunucu hatası | Log'lara bak (loguru app/logs/sfdap.log) |
Standart hata response'u:
{
"detail": "Not authenticated"
}Repo kökünde docs/api/SFDAP.postman_collection.json (varsa) Postman'e import edilebilir.
Yoksa Swagger'dan /openapi.json'u export edip Postman'in Import → OpenAPI özelliği ile yükleyin.
- Tüm yazma endpoint'leri
slowapiile rate-limit'lidir (varsayılan 100 req/min). - Tarih parametreleri ISO 8601 formatında (örn.
2026-04-30T15:00:00Z). - Pagination için
?skip=ve?limit=query parametreleri (çoğu list endpoint'inde). - CORS sadece
settings.CORS_ORIGINSlistesindeki origin'lere açık.