API Documentation

QR Code Generator REST API reference

Base URL

https://<your-worker>.workers.dev

Endpoints

GET /api/qr

Generate a QR code image from the supplied data.

Query Parameters

ParameterTypeRequiredDefaultDescription
datastringYes The text or URL to encode in the QR code (max 4 296 chars)
sizeintegerNo256 Width & height in pixels (32 – 2 048)
formatstringNopng Output format: png or svg
errorCorrectionLevelstringNoM Error correction: L, M, Q, or H
colorDarkstringNo#000000ff Foreground colour as hex (#RGB, #RGBA, #RRGGBB, or #RRGGBBAA)
colorLightstringNo#ffffffff Background colour as hex. Use #00000000 for transparent.
marginintegerNo2 Quiet zone in modules (0–10)

Response

Error Response

{
  "error": "Missing required parameter: data"
}

Errors return a JSON body with an appropriate HTTP status code (400 or 500).

Examples

cURL – PNG

curl "https://<your-worker>.workers.dev/api/qr?data=https://example.com&size=512" \
  -o qrcode.png

cURL – SVG

curl "https://<your-worker>.workers.dev/api/qr?data=Hello+World&format=svg" \
  -o qrcode.svg

cURL – Custom colours & margin

curl "https://<your-worker>.workers.dev/api/qr?data=hello&colorDark=%233b82f6ff&colorLight=%2300000000&margin=0" \
  -o qrcode-blue-transparent.png

JavaScript (Fetch)

const url = new URL('https://<your-worker>.workers.dev/api/qr');
url.searchParams.set('data', 'https://example.com');
url.searchParams.set('size', '300');

const img = document.createElement('img');
img.src = url.toString();
document.body.appendChild(img);

Python (requests)

import requests

resp = requests.get(
    "https://<your-worker>.workers.dev/api/qr",
    params={"data": "https://example.com", "size": 256, "format": "png"},
)
with open("qrcode.png", "wb") as f:
    f.write(resp.content)

CORS

All API responses include permissive CORS headers, allowing requests from any origin: