🔽 Explorer & Live Log
Pilih Wilayah
Cascading
1
Provinsi
2
Kab/Kota
3
Kecamatan
4
Kel/Desa
Kode Pos
—
—
API Request Log
0 requests
Belum ada request.
Pilih provinsi di atas untuk memulai.
Pilih provinsi di atas untuk memulai.
🔎 Pencarian Cepat
Cari Provinsi atau Kab/Kota
search.json
📡 Endpoint Reference
Endpoint Reference
REST · JSON · CORS
GET
/api/provinces.json
Semua provinsi
GET
/api/regencies/{kode_provinsi}.json
Kab/kota dalam provinsi
GET
/api/districts/{kode_kabupaten}.json
Kecamatan dalam kab/kota
GET
/api/villages/{kode_kecamatan}.json
Kelurahan/desa + kode pos
GET
/api/search.json
Index provinsi + kab/kota
GET
/api/meta.json
Metadata & statistik
💻 Contoh Penggunaan
Contoh Kode
const BASE = 'https://username.github.io/wilayah-indonesia-api/api'; // 1. Ambil semua provinsi const provinces = await fetch(`${BASE}/provinces.json`) .then(r => r.json()); // 2. Kab/kota dalam Jawa Barat (kode "32") const regencies = await fetch(`${BASE}/regencies/32.json`) .then(r => r.json()); // 3. Kecamatan dalam Kab. Bogor (kode "3201") const districts = await fetch(`${BASE}/districts/3201.json`) .then(r => r.json()); // 4. Kelurahan/desa + kode pos dalam Kec. Nanggung const villages = await fetch(`${BASE}/villages/320101.json`) .then(r => r.json()); // Tampilkan kode pos desa tertentu const desa = villages.find(v => v.name === 'MALASARI'); console.log(desa?.postal_code); // "16650"
import useSWR from 'swr'; const BASE = process.env.NEXT_PUBLIC_WILAYAH_API; const fetcher = (url: string) => fetch(url).then(r => r.json()); export function ProvinceSelect() { const { data: provinces, isLoading } = useSWR( `${BASE}/provinces.json`, fetcher ); if (isLoading) return <select disabled><option>Memuat…</option></select>; return ( <select> <option value="">Pilih Provinsi</option> {provinces?.map((p) => ( <option key={p.code} value={p.code}> {p.name} </option> ))} </select> ); }
$base = 'https://username.github.io/wilayah-indonesia-api/api'; // Ambil semua provinsi $provinces = json_decode( file_get_contents("$base/provinces.json"), true ); // Ambil kab/kota di Jawa Barat (kode "32") $regencies = json_decode( file_get_contents("$base/regencies/32.json"), true ); // Loop dan tampilkan hasil foreach ($regencies as $reg) { echo $reg['name'] . ' (' . $reg['type'] . ")\n"; } // Atau gunakan Guzzle untuk project besar: // $client = new GuzzleHttp\Client(['base_uri' => $base]); // $prov = json_decode($client->get('/provinces.json')->getBody(), true);