API Scriptleri & Entegrasyonlar – Teknik Eğitim Rehberi (2025)

İMRAN

Archive Forum Kurucu
Admin
Katılım
10 Nisan 2025
Mesajlar
1,654
Çözümler
1
Reaksiyon puanı
139
Konum
Türkiye
REST • JSON • Webhook • OAuth • Üçüncü Parti API’lar
API (Application Programming Interface), yazılımların birbirine veri göndermesi ve iletişim kurmasını sağlayan temel yapıdır. Bu rehber, API kullanımını, entegrasyon tekniklerini ve hazır script örneklerini tablolar hâlinde açıklar.

🧩 1️⃣ API Temelleri – HTTP Metodları

MetodKullanım AlanıÖrnek
GETVeri almaProfil bilgisi çekme
POSTVeri göndermeGiriş / kayıt işlemleri
PUTVeri güncellemeProfil güncelleme
DELETEVeri silmeHesap silme
PATCHKısmi updateKullanıcı bilgisi kısmi değişim

🟦 2️⃣ JavaScript – Fetch API Scriptleri




SenaryoKodAçıklama
GET Request```js
fetch('/api/user')
.then(r=>r.json())
.then(console.log)

Kod:
| POST Request | ```js
fetch('/api/login',{
 method:'POST',
 headers:{'Content-Type':'application/json'},
 body:JSON.stringify({email,pass})
})
``` | Form gönderme |
| Token ile istek | ```js
fetch('/api/data',{
 headers:{'Authorization':'Bearer '+token}
})
``` | JWT/Token doğrulama |

---

# 🟧 **3️⃣ Axios – Gelişmiş JS API Scriptleri**

| **Senaryo** | **Kod** | **Açıklama** |
|--------------|---------|--------------|
| GET | `axios.get('/users')` | En basit kullanım |
| POST | `axios.post('/login',{email,pass})` | Body gönderme |
| Header ile | ```js
axios.get('/data',{headers:{token}})
``` | Custom header |
| Global Config | ```js
axios.defaults.baseURL="/api";
``` | Tüm API ayarları |

---

# 🟩 **4️⃣ Node.js API Scriptleri (Backend)**

| **Script** | **Kod** | **Açıklama** |
|------------|----------|--------------|
| Basit API | ```js
app.get('/api', (req,res)=>res.json({ok:true}));
``` | Express API endpoint |
| JSON Gönderme | `res.json({name:"Ali"})` | JSON formatında cevap |
| Parametre | `req.params.id` | /user/12 gibi URL param |
| Body | `req.body` | POST verisini alma |

---

# 🟦 **5️⃣ Node.js – Dış API Entegrasyonları**

| **API Türü** | **Kod** | **Ne İşe Yarar?** |
|---------------|----------|--------------------|
| Hava Durumu API | ```js
const r = await axios.get('https://api.weather.com/...')``` | Hava bilgisi |
| Ödeme API (Stripe) | `stripe.charges.create({...})` | Kart ödeme alma |
| SMS API (Twilio) | `client.messages.create({...})` | SMS gönderme |
| Global REST API | `axios.get('https://jsonplaceholder.typicode.com/posts')` | Örnek veri çekme |

---

# 🟨 **6️⃣ Python – API Scriptleri**

| **Senaryo** | **Kod** | **Açıklama** |
|--------------|---------|--------------|
| GET Request | ```python
import requests
r=requests.get("https://api.test")
print(r.json())
``` | Veri çekme |
| POST Request | ```python
requests.post(url,json={"a":1})
``` | Veri gönderme |
| Token ile | ```python
requests.get(url,headers={"Authorization":token})
``` | Token doğrulama |

---

# 🟪 **7️⃣ PHP – cURL API Scriptleri**

| **Script** | **Kod** | **Açıklama** |
|------------|----------|--------------|
| GET | ```php
curl_setopt($ch, CURLOPT_URL, $url);
``` | API’den veri çekme |
| POST | ```php
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
``` | JSON gönderme |
| Token | ```php
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $token"]);
``` | Yetkili istek |

---

# 🔔 **8️⃣ Webhook Sistemleri**

| **Sistem** | **Açıklama** |
|------------|--------------|
| GitHub Webhook | Repo push → Sunucuya bildirim |
| Discord Webhook | Oyun / sistem olayları aktarma |
| Stripe Webhook | Ödeme sonrasında tetikleme |
| Telegram Bot | API → Telegram kanalına mesaj |

Webhook yapısı:

```js
app.post('/webhook', (req,res)=>{
 console.log("Webhook geldi:", req.body);
 res.sendStatus(200);
});

🔐 9️⃣ API Güvenlik Yapıları


Güvenlik KatmanıAçıklama
API KeySabit anahtar doğrulaması
JWT TokenKullanıcı doğrulama & yetki
Rate LimitFlood, DDoS önleme
IP WhitelistSadece izinli IP erişimi
HTTPSVeri şifreleme

🔥 API Rate Limit Sistemi (DDoS korumalı)​


JavaScript:
const rateLimit = require('express-rate-limit');

const limiter = rateLimit({
 windowMs: 60*1000,
 max: 50
});

app.use('/api/', limiter);

🔑 1️⃣1️⃣ OAuth 2.0 (Google, Discord, GitHub Login)

ServisEndpoint Türü
Google OAuth/auth/google
Discord OAuth/oauth2/authorize
GitHub OAuth/login/oauth/authorize
OAuth akışı:
  1. Kullanıcı sağlayıcıya yönlendirilir
  2. Kullanıcı izin verir
  3. API → server’a code gönderir
  4. Server code ile access token alır
  5. Server kullanıcı bilgilerini çekip hesap oluşturur

📦 1️⃣2️⃣ En Popüler Üçüncü Parti API Entegrasyon Tabloları

APIKullanım AlanıÖrnek
StripeÖdemeKart tahsilat
PayPalÖdemeAbonelik / shop
Google MapsHaritaKonum gösterme
YouTube APIVideoKanal verisi çekme
OpenAI APIAIChatbot / otomasyon
FirebaseAuth / DBMobil backend
SendGridEmailDoğrulama maili

🧠 1️⃣3️⃣ API Hata Yönetimi & Response Kodları

KodAnlamı
200 OKBaşarılı
201 CREATEDVeri oluşturuldu
400 BAD REQUESTEksik veri
401 UNAUTHORIZEDToken yok
403 FORBIDDENYetki yok
404 NOT FOUNDEndpoint yok
429 TOO MANY REQUESTSRate-limit
500 INTERNAL ERRORSunucu hatası
 
Geri
Üst Alt