Skip to content

Commit 18d7025

Browse files
authored
Update README.md
1 parent e63b8df commit 18d7025

1 file changed

Lines changed: 111 additions & 6 deletions

File tree

README.md

Lines changed: 111 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<img src="https://raw.githubusercontent.com/dyazincahya/API-KBBI-PHP-Codeigniter-4/main/kbbi.webp" width="150" />
22

3-
# Unofficial API Kamus Besar Bahasa Indonesia (KBBI) 2024
3+
# Unofficial API Kamus Besar Bahasa Indonesia (KBBI) 2026
44

55
```json
66
{
77
"api": {
8-
"name": "API KBBI 2024",
8+
"name": "API KBBI 2026",
99
"source": "https://kbbi.kemendikdasmen.go.id",
1010
"method": "HTML Parsing"
1111
},
@@ -15,7 +15,8 @@
1515
"library": [
1616
"CURL",
1717
"DOMDocument",
18-
"DOMXPath"
18+
"DOMXPath",
19+
"GeoNodeScraperAPI",
1920
]
2021
},
2122
"author": {
@@ -48,18 +49,122 @@ https://services.x-labs.my.id/kbbi/randomwords?limit=100
4849

4950
[Coba Sekarang](https://services.x-labs.my.id/kbbi/)
5051

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
5455

5556
## Pustaka yang digunakan
5657
- CURL
5758
- DOMDocument
5859
- 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+
---
59163

60164
## Cara Instalasi
61165
- Salin atau unduh kode model (Model) dengan nama [KBBIModel.php](https://github.com/dyazincahya/API-KBBI-PHP-Codeigniter-4/blob/main/KBBIModel.php)
62166
- 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)
63168
- Tambahkan baris router berikut pada file ```\app\Config\Routes.php```
64169
```php
65170
// KBBI Router : \Config\Routes.php

0 commit comments

Comments
 (0)