{% extends "base.html" %} {% block title %}API Documentation - {{ app_name }}{% endblock %} {% block content %}

API Documentation

RESTful API for programmatic access to geo-blocking configuration generation.

Base URL:
GET /api/countries Get available countries
Description

Returns a list of all available countries with their ISO codes and flag emojis.

Response Schema
{
  "success": true,
  "countries": [
    {
      "code": "CN",
      "name": "China",
      "flag": "🇨🇳"
    }
  ]
}
Try it out
GET /api/database/status Check database status
Description

Returns the current status of the MaxMind GeoIP database, including last update time and whether an update is needed.

Response Schema
{
  "success": true,
  "exists": true,
  "needs_update": false,
  "last_update": "2026-02-10T08:00:00",
  "file_size": 5242880,
  "auto_update": true
}
Try it out
POST /api/database/update Update database manually
Description

Manually triggers a download and update of the MaxMind GeoIP database from configured sources.

Response Schema
{
  "success": true,
  "url": "https://github.com/...",
  "size": 5242880
}
Try it out
GET /api/progress Get current generation progress
Description

Returns the current progress status of any active configuration generation process. Poll this endpoint to monitor long-running operations.

Response Schema
{
  "active": true,
  "message": "[1/3] CN: Scanning MaxMind: 234 networks found",
  "progress": 30,
  "total": 100
}
Fields
Name Type Description
active boolean Whether a generation process is currently active
message string Current progress message with detailed status
progress integer Current progress value (0-100)
total integer Total progress value (always 100)
Try it out
Polling Example
// Poll every 500ms during generation
const pollProgress = setInterval(async () => {
  const response = await fetch('/api/progress');
  const data = await response.json();
  
  if (data.active) {
    console.log(`Progress: ${data.progress}% - ${data.message}`);
  } else {
    clearInterval(pollProgress);
    console.log('Generation complete!');
  }
}, 500);
POST /api/generate/preview Preview configuration (JSON response)
Description

Generates configuration and returns it as JSON (instead of file download). Perfect for previewing or integrating into other applications.

Request Body
{
  "countries": ["CN", "RU"],
  "app_type": "nginx",
  "app_variant": "map",
  "aggregate": true,
  "use_cache": true
}
Parameters
Name Type Required Description
countries array required List of ISO 3166-1 alpha-2 country codes
app_type string required One of: nginx, apache, haproxy, raw-cidr
app_variant string required Configuration style (depends on app_type)
aggregate boolean optional Aggregate IP networks to reduce count (default: true)
use_cache boolean optional Use Redis cache if available (default: true). Set to false to force fresh data from SQLite/MaxMind
Response Schema
{
  "success": true,
  "config": "# Nginx Map Module Configuration\n...",
  "stats": {
    "countries": 2,
    "total_networks": 4567,
    "per_country": {
      "CN": 2834,
      "RU": 1733
    }
  },
  "from_cache": true,
  "cache_type": "redis",
  "generated_at": "2026-02-16T10:30:00"
}
Response Fields
Name Type Description
from_cache boolean Whether the config was served from cache or freshly generated
cache_type string redis (from Redis cache) or sqlite (from SQLite/fresh scan)
generated_at string ISO 8601 timestamp when the config was generated
cURL Examples

With cache (default):

curl -X POST /api/generate/preview \
  -H "Content-Type: application/json" \
  -d '{
    "countries": ["CN", "RU"],
    "app_type": "nginx",
    "app_variant": "map",
    "aggregate": true,
    "use_cache": true
  }' | jq .

Force fresh data (bypass cache):

curl -X POST /api/generate/preview \
  -H "Content-Type: application/json" \
  -d '{
    "countries": ["CN", "RU"],
    "app_type": "nginx",
    "app_variant": "map",
    "aggregate": true,
    "use_cache": false
  }' | jq .
POST /api/generate/raw Generate raw CIDR blocklist
Description

Generates a raw CIDR blocklist without application-specific configuration. Perfect for iptables, fail2ban, or custom implementations.

Request Body
{
  "countries": ["CN", "RU"],
  "app_variant": "txt",
  "aggregate": true,
  "use_cache": true
}
Parameters
Name Type Required Description
countries array required List of ISO 3166-1 alpha-2 country codes
app_variant string optional Output format: txt (default) or csv
aggregate boolean optional Aggregate IP networks (default: true)
use_cache boolean optional Use Redis cache if available (default: true)
Response

Returns plain text file with CIDR blocks (one per line) or CSV with CIDR and country columns.

Response Headers
Header Description
X-From-Cache true or false - indicates if served from Redis
X-Cache-Type redis or sqlite - data source type
X-Generated-At Timestamp when config was generated
cURL Examples

With cache (faster):

curl -X POST /api/generate/raw \
  -H "Content-Type: application/json" \
  -d '{
    "countries": ["CN", "RU"],
    "app_variant": "txt",
    "aggregate": true,
    "use_cache": true
  }' \
  -o blocklist.txt

Force fresh data (slower but guaranteed up-to-date):

curl -X POST /api/generate/raw \
  -H "Content-Type: application/json" \
  -d '{
    "countries": ["CN", "RU"],
    "app_variant": "txt",
    "aggregate": true,
    "use_cache": false
  }' \
  -o blocklist_fresh.txt
POST /api/generate Generate application configuration
Description

Generates application-specific geo-blocking configuration for Nginx, Apache, or HAProxy and returns it as a downloadable file.

Request Body
{
  "countries": ["CN", "RU"],
  "app_type": "nginx",
  "app_variant": "map",
  "aggregate": true,
  "use_cache": true
}
Parameters
Name Type Required Description
countries array required List of ISO 3166-1 alpha-2 country codes
app_type string required One of: nginx, apache, haproxy
app_variant string required Configuration style (depends on app_type)
aggregate boolean optional Aggregate IP networks (default: true)
use_cache boolean optional Use Redis cache if available (default: true)
Available Variants
  • nginx: geo, map, deny
  • apache: 22 (Apache 2.2), 24 (Apache 2.4)
  • haproxy: acl, lua
Response

Returns configuration file as text/plain with Content-Disposition header for download.

Response Headers
Header Description
X-From-Cache true or false
X-Cache-Type redis or sqlite
X-Generated-At ISO 8601 timestamp
Cache Behavior
With Redis enabled:
  • use_cache: true - Check Redis first, return cached config if available (fast, <1s)
  • use_cache: false - Bypass Redis, fetch from SQLite cache or scan MaxMind (slower, 5-30s)
cURL Examples

With cache (recommended for production):

curl -X POST /api/generate \
  -H "Content-Type: application/json" \
  -d '{
    "countries": ["CN", "RU"],
    "app_type": "nginx",
    "app_variant": "map",
    "aggregate": true,
    "use_cache": true
  }' \
  -o geoblock.conf

# Check if it was cached:
curl -I -X POST /api/generate \
  -H "Content-Type: application/json" \
  -d '{"countries":["CN"],"app_type":"nginx","app_variant":"map"}' \
  | grep "X-From-Cache"

Force fresh scan (for testing or updates):

curl -X POST /api/generate \
  -H "Content-Type: application/json" \
  -d '{
    "countries": ["CN", "RU"],
    "app_type": "nginx",
    "app_variant": "map",
    "aggregate": true,
    "use_cache": false
  }' \
  -o geoblock_fresh.conf
{% endblock %} {% block scripts %} {% endblock %}