api-wilayah

API Wilayah Indonesia

Node.js Express License Build Status GitHub issues GitHub contributors

GitHub forks GitHub stars

Overview

Another API Wilayah in Indonesia! But what makes this API project different?

Example endpoints for accessing the data:

Data Source: The data provided by this API is obtained from the official Indonesian government repository at https://katalog.satudata.go.id/organization/kementerian-dalam-negeri. While every effort has been made to ensure the accuracy and reliability of the data, it is provided on an “AS IS” basis without any warranties—either express or implied—regarding its completeness or suitability for any particular purpose. By using this API, you agree to verify and adhere to the data usage terms of the original source.

Table of Contents

Introduction

This project provides a RESTful API that serves detailed data on Indonesian administrative regions (provinces, regencies/cities, districts, and villages/sub-districts) along with demographic details such as population segmented by various age groups. The data is maintained and updated automatically via scraping scripts.

Features

Prerequisites

Installation

  1. Clone the Repository

    git clone https://github.com/IrvanFza/api-wilayah.git
    cd api-wilayah
    
  2. Install Dependencies

    npm install
    

Running the Project

Default: GitHub Pages API Access

In the default setup, the API is generated as static JSON files and hosted via GitHub Pages. The endpoints follow the pattern below:

Optional: Local Node & Express.js Server

If you prefer to serve the API using Node.js and Express, you can run the server as follows:

npm start

This starts the server on http://localhost:3000 with endpoints such as /api/provinsi (without the .json suffix).

If you start the server locally, you may want to use development mode with live reloading.

npm run dev

API Endpoints

The API provides the following endpoints (access format depends on your deployment):

Provinces (Provinsi)

Regencies/Cities (Kabupaten/Kota)

Districts (Kecamatan)

Villages/Sub-districts (Desa/Kelurahan)

Docker Deployment

You can deploy the API using Docker. Follow these steps:

  1. Build the Docker Image
docker build -t api-wilayah .
  1. Run the Docker Container
docker run -p 3000:3000 api-wilayah

Alternatively, use Docker Compose:

docker-compose up -d

The container will expose the API on port 3000.

GitHub Pages Bandwidth Restrictions

By default, this project is served through GitHub Pages for easier deployment, but it has some limitations.

GitHub Pages is primarily designed for hosting static content and may not be optimal for very high-volume API traffic. Although GitHub does not officially publish a fixed bandwidth quota for GitHub Pages, practical estimates and community experience can provide some guidance:

Note: These estimations are based on simplified calculations and current user experiences. Actual capacity can vary depending on file sizes, real-world traffic patterns, caching efficiency, and GitHub’s internal policies. It is advised to monitor your API’s traffic and performance regularly.

Data Scraping

Data is scraped with custom scripts located in the scraper/ directory. These scripts fetch regional and demographic data from the official Ministry of Home Affairs (Kemendagri) API.

Manual Data Update

  1. Run the Regional Data Scraper
node scraper/regionalDataScraper.js
  1. Run the Population Data Scraper
node scraper/populationDataScraper.js
  1. Merge the Data
node scraper/mergeData.js

Automated Data Update

Automated updates are set up using GitHub Actions. The workflow defined in .github/workflows/scraper.yml performs the following steps:

Project Structure

api-wilayah/
├── .github/
│   └── workflows/
│       └── scraper.yml          # GitHub Actions workflow for automated data scraping
├── api/                         # Generated JSON API for GitHub Pages
├── data
│   └── json
│       ├── population
│       └── region
├── docker-compose.yml
├── scraper
│   ├── populationDataScraper.js
│   ├── regionDataScraper.js
│   └── utils
│       ├── fileHelper.js
│       ├── kemendagriAPIClient.js
│       ├── mergeData.js
│       └── splitData.js
├── src/                         # Node.js/Express server code (optional for local API access)
|   ├── app.js
|   ├── server.js
|   |── utils
|   |   └── createFilteredRoute.js
|   └── routes
|       ├── desaKelurahan.js
|       ├── index.js
|       ├── kabupatenKota.js
|       ├── kecamatan.js
|       └── provinsi.js
├── Dockerfile                   # Dockerfile for containerized deployment
├── docker-compose.yml          # Docker Compose configuration
├── package.json
└── README.md

Contributing

Contributions are welcome! To contribute to this project, please follow these steps:

  1. Fork the Repository

    Click the Fork button at the top-right corner of this page to create a copy of the repository on your account.

  2. Clone Your Fork

    git clone https://github.com/IrvanFza/api-wilayah.git
    cd api-wilayah
    
  3. Create a New Branch

    git checkout -b feature/your-feature-name
    
  4. Make Your Changes

    Implement your feature or bug fix.

  5. Commit Your Changes

    git commit -m "Add your feature description"
    
  6. Push to Your Branch

    git push origin feature/your-feature-name
    
  7. Submit a Pull Request

    Go to the original repository and click on Pull Requests, then click on New Pull Request.

TODO

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Sponsorship

If you find this project useful and would like to support its ongoing development, please consider donating or sponsoring through the following platforms: