Fetches JSON from an HTTP API and inserts the raw response into a PostgreSQL table. Ideal for one-off or scheduled ETL (e.g. cron, Kubernetes CronJob).
What it does: GETs SITE_URL → parses JSON → inserts the full payload into TABLE_NAME.raw_json.
Your PostgreSQL table must already exist and have a raw_json column (e.g. TEXT or JSONB).
docker run --rm \
-e SITE_URL="https://api.example.com/data" \
-e DATABASE_URL="postgresql://user:password@host:5432/mydb" \
-e TABLE_NAME="my_data" \
your-dockerhub-username/api2db
docker pull your-dockerhub-username/api2db
| Variable | Required | Description |
|---|---|---|
SITE_URL | Yes | API URL to fetch (GET). |
DATABASE_URL | Yes | PostgreSQL connection string (postgresql://user:pass@host:port/dbname). |
TABLE_NAME | Yes | Table name. Must have a raw_json column. |
HEADER_KEYS | No | JSON object of HTTP headers. Default: {}. |
DEBUG | No | Set to true to log a sample of the response. Default: false. |
docker run --rm --env-file .env your-dockerhub-username/api2db
Example .env:
SITE_URL=https://api.example.com/v1/records
DATABASE_URL=postgresql://user:[email protected]:5432/etl
TABLE_NAME=api_snapshots
HEADER_KEYS={"Authorization": "Bearer YOUR_TOKEN", "Accept": "application/json"}
DEBUG=false
Create the table before running the container:
CREATE TABLE my_data (
id SERIAL PRIMARY KEY,
raw_json JSONB,
created_at TIMESTAMPTZ DEFAULT NOW()
);
With Docker, you can run it on a schedule (e.g. host cron):
0 * * * * docker run --rm -e SITE_URL=... -e DATABASE_URL=... -e TABLE_NAME=... your-dockerhub-username/api2db
Or use the same image as the job container in a Kubernetes CronJob.
Content type
Image
Digest
sha256:d0b0c5b0c…
Size
201.8 MB
Last updated
6 months ago
docker pull lucascordova/api2db