{% extends "base.html" %} {% block title %}API Documentation - {{ app_name }}{% endblock %} {% block content %}
RESTful API for programmatic access to geo-blocking configuration generation.
/api/countries
Get available countries
Returns a list of all available countries with their ISO codes and flag emojis.
{
"success": true,
"countries": [
{
"code": "CN",
"name": "China",
"flag": "🇨🇳"
}
]
}
/api/database/status
Check database status
Returns the current status of the MaxMind GeoIP database, including last update time and whether an update is needed.
{
"success": true,
"exists": true,
"needs_update": false,
"last_update": "2026-02-10T08:00:00",
"file_size": 5242880,
"auto_update": true
}
/api/database/update
Update database manually
Manually triggers a download and update of the MaxMind GeoIP database from configured sources.
{
"success": true,
"url": "https://github.com/...",
"size": 5242880
}
/api/progress
Get current generation progress
Returns the current progress status of any active configuration generation process. Poll this endpoint to monitor long-running operations.
{
"active": true,
"message": "[1/3] CN: Scanning MaxMind: 234 networks found",
"progress": 30,
"total": 100
}
| 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) |
// 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);
/api/generate/preview
Preview configuration (JSON response)
Generates configuration and returns it as JSON (instead of file download). Perfect for previewing or integrating into other applications.
{
"countries": ["CN", "RU"],
"app_type": "nginx",
"app_variant": "map",
"aggregate": true,
"use_cache": true
}
| 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 |
{
"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"
}
| 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 |
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 .
/api/generate/raw
Generate raw blocklist (TXT/CSV/JSON/JS)
Generates a raw blocklist without application-specific configuration. Use this endpoint for programmatic integrations when you need structured output (JSON) or a JS-wrapped JSON payload.
{
"countries": ["CN", "RU"],
"app_type": "raw-json",
"aggregate": true,
"use_cache": true,
"as_js": false,
"js_var": "geoipBlocklist"
}
| Name | Type | Required | Description |
|---|---|---|---|
countries |
array | required | List of ISO 3166-1 alpha-2 country codes |
app_type |
string | optional |
Output format selector. Examples:
raw-json (JSON), raw-json + as_js=true (JS wrapper).
|
aggregate |
boolean | optional | Aggregate IP networks (default: true) |
use_cache |
boolean | optional | Use Redis cache if available (default: true) |
Only for raw-json.
When true, wraps JSON into JavaScript and returns application/javascript as:
const <js_var> = {...};
|
|||
js_var |
string | optional |
Variable name used by as_js wrapper (default: geoipBlocklist).
|
| Mode | Content-Type | Body |
|---|---|---|
raw-cidr_txt |
text/plain |
One CIDR per line |
raw-cidr_csv |
text/csv |
CSV export |
raw-cidr_json |
application/json |
JSON object with countries, networks, count, aggregated |
raw-cidr_json + as_js=true |
application/javascript |
const <js_var> = {...}; |
| Mode | Content-Type | Body |
|---|---|---|
raw-cidr_txt |
text/plain |
One CIDR per line |
raw-cidr_csv |
text/csv |
CSV export |
raw-json |
application/json |
JSON object with generated_at, countries, networks, total_networks |
raw-json + as_js=true |
application/javascript |
const <js_var> = {...}; |
| Header | Description |
|---|---|
X-From-Cache |
true or false - indicates if served from Redis |
X-Cache-Type |
redis-full or computed cache type (e.g. hybrid) |
X-Generated-At |
Timestamp when config was generated |
TXT (default):
curl -X POST /api/generate/raw \
-H "Content-Type: application/json" \
-d '{
"countries": ["CN", "RU"],
"app_type": "raw-cidr_txt",
"aggregate": true,
"use_cache": true
}' \
-o blocklist.txt
CSV:
curl -X POST /api/generate/raw \
-H "Content-Type: application/json" \
-d '{
"countries": ["CN", "RU"],
"app_type": "raw-cidr_csv",
"aggregate": true,
"use_cache": true
}' \
-o blocklist.csv
JSON:
curl -X POST /api/generate/raw \
-H "Content-Type: application/json" \
-d '{
"countries": ["CN", "RU"],
"app_type": "raw-json",
"aggregate": true,
"use_cache": true
}' \
-o blocklist.json
JS-wrapped JSON:
curl -X POST /api/generate/raw \
-H "Content-Type: application/json" \
-d '{
"countries": ["CN", "RU"],
"app_type": "raw-json",
"aggregate": true,
"use_cache": true,
"as_js": true,
"js_var": "geoipBlocklist"
}' \
-o blocklist.js
/api/generate
Generate application configuration
Generates application-specific geo-blocking configuration for Nginx, Apache, or HAProxy and returns it as a downloadable file.
{
"countries": ["CN", "RU"],
"app_type": "nginx",
"app_variant": "map",
"aggregate": true,
"use_cache": true
}
| 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) |
geo, map, deny22 (Apache 2.2), 24 (Apache 2.4)acl, lua, mapReturns configuration file as text/plain with Content-Disposition header for download.
| Header | Description |
|---|---|
X-From-Cache |
true or false |
X-Cache-Type |
redis or sqlite |
X-Generated-At |
ISO 8601 timestamp |
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)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