Skip to content
/ api Public

The API for Indonesian public transportation data, built using Hono

Notifications You must be signed in to change notification settings

comuline/api

Repository files navigation

@comuline/api

An API to get the schedule of KRL commuter line in Jakarta and Yogyakarta using Hono and Bun, deployed to Cloudflare Workers. This API is primarily used on the web app (source code).

How does it work?

This API uses a daily cron job (at 00:00) to fetch the schedule of KRL commuter line in Jakarta and Yogyakarta from the official website of PT. KAI. The data is then processed and stored in a PostgreSQL database and cached in a Redis (for every once read request). All endpoints can be found in the docs.

Technology stacks

  1. Hono API framework
  2. Bun runtime
  3. (Serverless) PostgresSQL (Neon)
  4. (Serverless) Redis (Upstash)
  5. Cloudflare Workers deployment platform
  6. Drizzle ORM

Getting Started

Development

  1. Clone the repository
git clone https://github.com/comuline/api.git
  1. Install the dependencies
bun install
  1. Copy the .dev.example.vars to .dev.vars
cp .dev.example.vars .dev.vars
  1. Generate UPSTASH_REDIS_REST_TOKEN using openssl rand -hex 32 and copy it to your .dev.vars file

  2. Run database locally

docker-compose up -d
  1. Run the database migration
bun run migrate:apply
  1. Sync the data and populate it into your local database (once only as you needed)
# Please do this in order
# 1. Sync station data and wait until it's done
bun run sync:station
# 2. Sync schedule data
bun run sync:schedule

Deployment

  1. Rename the wrand.example.toml to wrangler.toml and fill the necessary information

  2. Create a new PostgreSQL database in Neon and copy the connection string value as DATABASE_URL in your .production.vars file

  3. Run the database migration

bun run migrate:apply
  1. Sync the data and populate it into your remote database (once only as you needed)
# Please do this in order
# 1. Sync station data and wait until it's done
bun run sync:station
# 2. Sync schedule data
bun run sync:schedule
  1. Add COMULINE_ENV to your .production.vars file
COMULINE_ENV=production
  1. Create a new Redis database in Upstash and copy the value of UPSTASH_REDIS_REST_TOKEN and UPSTASH_REDIS_REST_URL to your .production.vars file

  2. Save your .production.vars file to your environment variables in your Cloudflare Workers using wrangler

bunx wrangler secret put --env production $(cat .production.vars)
  1. Deploy the API to Cloudflare Workers
bun run deploy

Database schema

TBD

About

The API for Indonesian public transportation data, built using Hono

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •