Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/dadu0699/qr-code/llms.txt

Use this file to discover all available pages before exploring further.

The /api/qr/generate endpoint accepts a URL and returns a complete SVG document encoding that URL as a QR code. The SVG can be embedded inline in HTML, served as a file download, or converted to a raster image. Call this endpoint whenever you need a scannable QR code at runtime — no pre-generation or storage required.
POST /api/qr/generate

Request

Headers

HeaderValueRequired
Content-Typeapplication/jsonYes

Body

url
string
required
The HTTP or HTTPS URL to encode in the QR code. Must be a valid absolute URL — relative paths are not accepted. Maximum length is 2048 characters. URLs using any protocol other than http: or https: (e.g. ftp://, file://) are rejected.
color
object
Optional color overrides for the QR code. When omitted, the default dark-on-light palette is used (#000000 on #FFFFFF).
In the underlying qrcode library, dark refers to the QR modules (foreground) and light refers to the background. For maximum scanner compatibility, keep sufficient contrast between the two colors — dark modules on a light background is the conventional choice.

Response

200 OK

Returns the QR code as an SVG document.
HeaderValue
Content-Typeimage/svg+xml
body
string
A complete SVG document string. The root element is <svg xmlns="http://www.w3.org/2000/svg" ...> containing the QR code paths rendered at the requested colors. The response body is plain text — read it with response.text(), not response.json().
Example response (excerpt):
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 37 37" ...>...</svg>

Error Responses

StatusError messageCause
400Invalid JSON bodyRequest body is not valid JSON
400Invalid request bodyBody is not a JSON object
400URL is requiredurl field is missing or empty
400URL exceeds maximum length of 2048 charactersURL is longer than 2048 characters
400Invalid URLurl is not a valid absolute URL
400URL protocol must be http or httpsurl uses ftp://, file://, or another non-HTTP protocol
400Invalid colorcolor field is present but is not an object
400Invalid dark colorcolor.dark is not a valid hex color string
400Invalid light colorcolor.light is not a valid hex color string
500Failed to generate QR codeInternal QR generation error
All error responses have Content-Type: application/json and the body shape { "error": "<message>" }.

Code Examples

curl -X POST https://your-worker.workers.dev/api/qr/generate \
  -H 'Content-Type: application/json' \
  -d '{"url": "https://github.com/dadu0699/qr-code"}'

CORS and OPTIONS

Like all API endpoints, /api/qr/generate includes CORS headers on every response:
HeaderValue
Access-Control-Allow-MethodsPOST, OPTIONS
Access-Control-Allow-HeadersContent-Type
Access-Control-Max-Age86400
VaryOrigin
Access-Control-Allow-Origin is reflected only when the request Origin matches an entry in the ALLOWED_ORIGINS Worker environment variable. Sending an OPTIONS request to this endpoint returns 204 No Content with the same CORS headers — no body — to satisfy browser preflight checks.
The SVG response can be used in two ways without any further processing. Inline: set the raw SVG string as the innerHTML of a container element for full CSS control. Image tag: encode the SVG as a data URI — data:image/svg+xml;charset=utf-8,<url-encoded-svg> — and use it as the src of an <img> element for easy sizing and lazy loading.

Build docs developers (and LLMs) love