Tutorial Penggunaan API untuk Pemula
Panduan lengkap cara menggunakan StreamAPI dari nol sampai mahir
Step 1: Dapatkan API Key
- Daftar akun di StreamAPI
- Beli API Key untuk folder yang diinginkan (Rp 50.000/bulan)
- Bayar via QRIS menggunakan payment gateway Pakasir
- Setelah pembayaran berhasil, Anda akan mendapat API Key
- PENTING: Simpan API Key dengan aman, tidak akan ditampilkan lagi!
Catatan: API Key berlaku 30 hari dan tidak auto-renew. Anda harus membeli ulang setelah expired.
Step 2: Cara Menggunakan API
Format Request
Semua request API harus menyertakan API Key di header:
Metode 1 - Parameter URL:
URL: https://streamapi.web.id/api-folder/endpoint.php?api_key=your_api_key_here
Metode 2 - Header HTTP:
Header: X-API-Key: your_api_key_here
URL: https://streamapi.web.id/api-folder/endpoint.php
Contoh Endpoint
# Anime Populer
GET https://streamapi.web.id/api-anime/populer.php
# Anime by Genre
GET https://streamapi.web.id/api-anime/genre.php?genre=romance&page=1
# Detail Anime
GET https://streamapi.web.id/api-anime/anime.php?slug=anime-slug
# Episode Detail
GET https://streamapi.web.id/api-anime/episode.php?slug=episode-slug
Step 3: Contoh Code Implementation
PHP (cURL)
<?php
$apiKey = 'your_api_key_here';
// Metode 1: Parameter URL
$url = 'https://streamapi.web.id/api-anime/populer.php?api_key=' . $apiKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Metode 2: Header HTTP
$url = 'https://streamapi.web.id/api-anime/populer.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: ' . $apiKey
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$data = json_decode($response, true);
print_r($data);
} else {
echo "Error: HTTP $httpCode";
}
?>
JavaScript (Fetch API)
const apiKey = 'your_api_key_here';
// Metode 1: Parameter URL
const url1 = `https://streamapi.web.id/api-anime/populer.php?api_key=${apiKey}`;
fetch(url1)
// Metode 2: Header HTTP
const url2 = 'https://streamapi.web.id/api-anime/populer.php';
fetch(url2, {
method: 'GET',
headers: {
'X-API-Key': apiKey
}
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return response.json();
})
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});
Python (Requests)
import requests
import json
api_key = 'your_api_key_here'
# Metode 1: Parameter URL
url1 = f'https://streamapi.web.id/api-anime/populer.php?api_key={api_key}'
response1 = requests.get(url1)
# Metode 2: Header HTTP
url2 = 'https://streamapi.web.id/api-anime/populer.php'
headers = {
'X-API-Key': api_key
}
response2 = requests.get(url2, headers=headers)
if response.status_code == 200:
data = response.json()
print(json.dumps(data, indent=2))
else:
print(f"Error: HTTP {response.status_code}")
cURL (Command Line)
Dengan Parameter:
curl -X GET "https://streamapi.web.id/api-anime/populer.php?api_key=your_api_key_here"
Dengan Header:
curl -X GET "https://streamapi.web.id/api-anime/populer.php" \
-H "X-API-Key: your_api_key_here" \
-H "Content-Type: application/json"
Step 4: Format Response
Success Response
{
"status": "success",
"data": {
"genre": "romance",
"title": "Romance Anime",
"page": 1,
"total_item": 20,
"items": [
{
"title": "Anime Title",
"slug": "anime-slug",
"image": "image_url",
"type": "TV",
"status": "Ongoing"
}
]
}
}
Error Response
{
"error": "Invalid or expired API Key"
}
HTTP Status Codes
- 200 - Success
- 400 - Bad Request (parameter salah)
- 401 - Unauthorized (API Key tidak ada)
- 403 - Forbidden (API Key invalid/expired)
- 404 - Not Found (endpoint tidak ada)
- 500 - Internal Server Error
Step 5: Error Handling
Contoh Error Handling (PHP)
<?php
function callAPI($endpoint, $apiKey) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: ' . $apiKey
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
switch ($httpCode) {
case 200:
return json_decode($response, true);
case 401:
throw new Exception('API Key required');
case 403:
throw new Exception('Invalid or expired API Key');
case 404:
throw new Exception('Endpoint not found');
default:
throw new Exception("HTTP Error: $httpCode");
}
}
try {
$data = callAPI('https://streamapi.web.id/api-anime/populer.php', 'your_api_key');
echo json_encode($data, JSON_PRETTY_PRINT);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>
Step 6: Best Practices
- Keamanan API Key: Jangan expose API key di frontend/client-side code
- Environment Variables: Simpan API key di environment variables
- Error Handling: Selalu handle error response dengan proper
- Rate Limiting: Meskipun unlimited, gunakan dengan bijak
- Caching: Cache response untuk mengurangi request yang tidak perlu
- Timeout: Set timeout untuk request (30 detik recommended)
- Logging: Log API calls untuk debugging
- Monitoring: Monitor usage di dashboard StreamAPI
FAQ - Pertanyaan Sering Ditanya
Q: Bagaimana cara mendapatkan API Key?
A: Daftar akun → Beli API Key → Bayar via QRIS → Dapatkan API Key
Q: Berapa lama API Key berlaku?
A: 30 hari dari tanggal pembelian, tidak auto-renew
Q: Apakah ada batasan request?
A: Tidak ada batasan, unlimited request selama API Key aktif
Q: Bisa beli API Key untuk multiple folder?
A: Ya, bisa beli terpisah untuk setiap folder API
Q: Bagaimana jika API Key expired?
A: Harus beli ulang, tidak ada auto-renew
Q: Bisa refund jika tidak puas?
A: Tidak ada refund, pastikan test API terlebih dahulu