|
1 | 1 | <img src="https://raw.githubusercontent.com/dyazincahya/API-KBBI-PHP-Codeigniter-4/main/kbbi.webp" width="150" /> |
2 | 2 |
|
3 | | -# Unofficial API Kamus Besar Bahasa Indonesia (KBBI) 2024 |
| 3 | +# Unofficial API Kamus Besar Bahasa Indonesia (KBBI) 2026 |
4 | 4 |
|
5 | 5 | ```json |
6 | 6 | { |
7 | 7 | "api": { |
8 | | - "name": "API KBBI 2024", |
| 8 | + "name": "API KBBI 2026", |
9 | 9 | "source": "https://kbbi.kemendikdasmen.go.id", |
10 | 10 | "method": "HTML Parsing" |
11 | 11 | }, |
|
15 | 15 | "library": [ |
16 | 16 | "CURL", |
17 | 17 | "DOMDocument", |
18 | | - "DOMXPath" |
| 18 | + "DOMXPath", |
| 19 | + "GeoNodeScraperAPI", |
19 | 20 | ] |
20 | 21 | }, |
21 | 22 | "author": { |
@@ -48,18 +49,122 @@ https://services.x-labs.my.id/kbbi/randomwords?limit=100 |
48 | 49 |
|
49 | 50 | [Coba Sekarang](https://services.x-labs.my.id/kbbi/) |
50 | 51 |
|
51 | | -## Kompatibel dengan |
52 | | -- PHP 8.3.8 |
53 | | -- Codeigniter 4.3.8 atau lebih baru |
| 52 | +## Kompatibel dan sudah di test pada |
| 53 | +- PHP 8.5 |
| 54 | +- Codeigniter 4.7.3 atau lebih baru |
54 | 55 |
|
55 | 56 | ## Pustaka yang digunakan |
56 | 57 | - CURL |
57 | 58 | - DOMDocument |
58 | 59 | - DOMXPath |
| 60 | +- GeoNode Scraper API (sebagai Fallback) |
| 61 | + |
| 62 | +## Alur Kerja Pengambilan Data (Scraping Workflow) |
| 63 | + |
| 64 | +Untuk menjaga performa dan efisiensi kuota, API ini menggunakan 3 lapis alur kerja cerdas saat mencari sebuah kata: |
| 65 | + |
| 66 | +1. **Lapis 1 - Scraping Langsung (Direct Request):** Jika data belum ada di database, sistem mencoba melakukan koneksi cURL langsung ke situs resmi KBBI. Ini gratis dan tanpa batas (cocok untuk localhost). |
| 67 | +2. **Lapis 2 - Fallback GeoNode Scraper API (Automated):** Jika koneksi langsung di atas gagal atau mengalami timeout (terutama saat dideploy di server VPS yang diblokir oleh WAF KBBI), sistem akan otomatis masuk ke blok `catch` dan mengalihkan request menggunakan **GeoNode Scraper API** via Proxy Residential. |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## 🔌 Integrasi GeoNode Scraper API (Bypass Blokir IP Server) |
| 72 | + |
| 73 | +<img width="1526" height="629" alt="image" src="https://github.com/user-attachments/assets/900b3c8b-a1c9-45f1-be09-bce4095aa3c0" /> |
| 74 | + |
| 75 | + |
| 76 | +Untuk melewati pemblokiran IP Data Center di server hosting/staging, sistem ini telah dilengkapi dengan library integrasi GeoNode Scraper API. |
| 77 | + |
| 78 | +### 1. Cara Mendapatkan API Key Gratis |
| 79 | +1. Buka dan daftar akun di website **[GeoNode Scraper API](https://app.geonode.com/scraper-api)**. |
| 80 | +2. Selesaikan proses registrasi dan verifikasi email Anda. |
| 81 | +3. Setelah masuk ke Dashboard, Anda akan mendapatkan **API Key** unik Anda. |
| 82 | +4. Salin API Key tersebut dan masukkan ke dalam file `app/Libraries/GeoNodeScraperAPI.php` pada bagian: |
| 83 | + ```php |
| 84 | + private string $apiKey = 'MASUKKAN_API_KEY_ANDA_DI_SINI'; |
| 85 | + ``` |
| 86 | + |
| 87 | +### 2. Jatah Kuota & Limitasi |
| 88 | +* **Limit Gratis:** Setiap akun baru mendapatkan jatah **1.500 request gratis setiap bulan** yang akan di-renew secara otomatis setiap bulannya. |
| 89 | +* **Fitur Safety Capping (Pembatas Lokal):** Library `GeoNodeScraperAPI` dilengkapi pengaman di `writable/geonode_limit.json`. Sistem akan otomatis memblokir request ke GeoNode jika hit bulanan lokal telah menyentuh **1.499 request** agar kuota gratis Anda tidak terlampaui. |
| 90 | + |
| 91 | +### 3. File Library Baru (`app/Libraries/GeoNodeScraperAPI.php`) |
| 92 | +Pastikan file ini dibuat untuk menangani pengiriman request API, rotasi proxy residensial, dan pencatatan limit bulanan: |
| 93 | + |
| 94 | +```php |
| 95 | +<?php |
| 96 | + |
| 97 | +namespace App\Libraries; |
| 98 | + |
| 99 | +use Exception; |
| 100 | + |
| 101 | +class GeoNodeScraperAPI |
| 102 | +{ |
| 103 | + private string $apiKey = 'MASUKKAN_API_KEY_ANDA_DI_SINI'; |
| 104 | + private string $apiUrl = 'https://scraper.geonode.io/v1/extract'; |
| 105 | + |
| 106 | + public function scrape(string $targetUrl): string |
| 107 | + { |
| 108 | + if (empty($this->apiKey) || $this->apiKey == 'MASUKKAN_API_KEY_ANDA_DI_SINI') { |
| 109 | + throw new Exception('GeoNode Scraper API Key is not configured.'); |
| 110 | + } |
| 111 | + |
| 112 | + $limitFile = WRITEPATH . 'geonode_limit.json'; |
| 113 | + $currentMonth = date('Y-m'); |
| 114 | + $count = 0; |
| 115 | + |
| 116 | + if (file_exists($limitFile)) { |
| 117 | + $data = json_decode(file_get_contents($limitFile), true); |
| 118 | + if (isset($data['month']) && $data['month'] === $currentMonth) { |
| 119 | + $count = (int)($data['count'] ?? 0); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + if ($count >= 1499) { |
| 124 | + throw new Exception('GeoNode Scraper API limit reached (max 1499 requests/month).'); |
| 125 | + } |
| 126 | + |
| 127 | + $postData = [ |
| 128 | + 'url' => $targetUrl, |
| 129 | + 'formats' => ['html'], |
| 130 | + 'render_js' => false, |
| 131 | + 'processing_mode' => 'sync', |
| 132 | + 'proxy' => [ |
| 133 | + 'country' => 'US', |
| 134 | + 'type' => 'datacenter' |
| 135 | + ] |
| 136 | + ]; |
| 137 | + |
| 138 | + $ch = curl_init($this->apiUrl); |
| 139 | + // ... (konfigurasi cURL & increment count jika sukses) |
| 140 | + } |
| 141 | +} |
| 142 | +``` |
| 143 | + |
| 144 | +### 4. Integrasi ke Model (`app/Models/KBBIModel.php`) |
| 145 | +Di dalam model, request cURL langsung dibungkus dalam blok `try-catch` seperti berikut untuk mengaktifkan fitur fallback otomatis: |
| 146 | + |
| 147 | +```php |
| 148 | +private function _fetchHtml($word) |
| 149 | +{ |
| 150 | + try { |
| 151 | + // ... (mencoba request langsung ke server KBBI) |
| 152 | + return $response; |
| 153 | + } catch (Exception $e) { |
| 154 | + // Fallback otomatis jika koneksi langsung gagal |
| 155 | + $targetUrl = 'https://kbbi.kemendikdasmen.go.id/entri/' . rawurlencode($word); |
| 156 | + $geoNode = new \App\Libraries\GeoNodeScraperAPI(); |
| 157 | + return $geoNode->scrape($targetUrl); |
| 158 | + } |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +--- |
59 | 163 |
|
60 | 164 | ## Cara Instalasi |
61 | 165 | - Salin atau unduh kode model (Model) dengan nama [KBBIModel.php](https://github.com/dyazincahya/API-KBBI-PHP-Codeigniter-4/blob/main/KBBIModel.php) |
62 | 166 | - Salin atau unduh kode kontroler (Controller) dengan nama [ApiKBBI.php](https://github.com/dyazincahya/API-KBBI-PHP-Codeigniter-4/blob/main/ApiKBBI.php) |
| 167 | +- Salin atau unduh kode pustaka (Library) dengan nama [GeoNodeScraperAPI.php](https://github.com/dyazincahya/API-KBBI-PHP-Codeigniter-4/blob/main/GeoNodeScraperAPI.php) |
63 | 168 | - Tambahkan baris router berikut pada file ```\app\Config\Routes.php``` |
64 | 169 | ```php |
65 | 170 | // KBBI Router : \Config\Routes.php |
|
0 commit comments