Cóid QR d'Fhorbróirí: REST API, SDK agus CLI

Conas cóid QR a ghiniúint go ríomhchláraithe, iad a chomhtháthú i d'fheidhmchlár, agus freagairt do scanadh trí webhooks — léargas teicniúil domhain.

le qr3.app Team

Cóid QR d'Fhorbróirí: REST API, SDK agus CLI

Mar fhorbróir, níl uait cóid QR a chruthú de láimh trí dheais — is mian leat iad a ghiniúint go huathoibríoch, iad a chomhtháthú i do phíblíne tógála, agus freagairt do scanadh trí webhooks. Sin go díreach an rud ar tógadh qr3.app dó.

An Cruach

Tá qr3.app go hiomlán dúchasach do Cloudflare:

  • API Worker: Hono ar Cloudflare Workers (am rite V8, gan aon spleáchais Node.js)
  • Redirect Worker: worker thar a bheith éadrom, atreoruithe taiscthe i KV i < 5ms p50
  • Bunachar Sonraí: Cloudflare D1 (SQLite) le hiltionóntacht trí workspace_id
  • Scuaine: imeachtaí scanta dícheangailte trí Cloudflare Queues

Fíordheimhniú

Teastaíonn comhartha Bearer agus aitheantas spáis oibre ó gach iarratas API:

POST https://qr3.app/v1/codes
Authorization: Bearer qr3_sk_...
Content-Type: application/json

Cruthaigh eochracha API ag app.qr3.app/dashboard/api-keys.

SDK TypeScript

npm install @qr3/sdk
# nó
pnpm add @qr3/sdk
import { QR3 } from "@qr3/sdk";

const client = new QR3({
  apiKey: process.env.QR3_API_KEY!,
  workspaceId: process.env.QR3_WORKSPACE_ID!,
});

// Create a QR code
const { data: code } = await client.codes.create({
  type: "url",
  url: "https://my-shop.com/product/42",
  title: "Product 42",
  tags: ["shop", "product"],
});

console.log(code.short_code);       // "r7f3Kx"
console.log(code.image_svg_url);    // SVG image URL
console.log(code.redirect_url);     // https://qr3.app/r7f3Kx

// Change URL later (dynamic codes only)
await client.codes.update(code.id, {
  url: "https://my-shop.com/product/42-new",
});

// Query analytics
const stats = await client.codes.stats(code.id, {
  from: "2026-01-01",
  to: "2026-03-31",
});
console.log(stats.data.total_scans); // e.g. 1247

REST API go Díreach

Gan spleáchas SDK? Tá an REST API inúsáidte go díreach:

# Create a QR code
curl -X POST https://qr3.app/v1/codes \
  -H "Authorization: Bearer $QR3_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "url",
    "url": "https://my-site.com",
    "title": "My Site",
    "is_dynamic": true
  }'

# List all QR codes
curl https://qr3.app/v1/codes?limit=20 \
  -H "Authorization: Bearer $QR3_API_KEY"

# Download QR code as SVG (with logo overlay)
curl "https://qr3.app/v1/codes/r7f3Kx/qr.svg?size=8&logo_url=https://mylogo.com/logo.png" \
  -o qrcode.svg

CLI

Le haghaidh scriptithe agus CI/CD tá an @qr3/cli ann:

npm install -g @qr3/cli
qr3 login

# Create QR code and save as SVG
qr3 codes create --url "https://my-site.com" --title "CI Deploy" --output qr.svg

# Batch creation from CSV
qr3 codes batch import urls.csv --format svg --output ./qr-codes/

Webhooks: Freagair do Scanadh

Is iad na webhooks an ghné is cumhachtaí: is féidir leat freagairt i bhfíor-am do gach scanadh.

// Register a webhook
const { data: webhook } = await client.webhooks.create({
  url: "https://your-app.com/webhooks/qr3",
  events: ["scan.created", "code.updated"],
});

Pálasta an Webhook

{
  "event": "scan.created",
  "timestamp": "2026-03-15T14:30:00Z",
  "data": {
    "code_id": "code_abc123",
    "short_code": "r7f3Kx",
    "country": "DE",
    "city": "Berlin",
    "device": "mobile",
    "os": "iOS",
    "browser": "Safari"
  }
}

Webhooks a Fhíorú (HMAC)

import { createHmac } from "crypto";

export async function verifyWebhook(
  payload: string,
  signature: string,
  secret: string,
): Promise<boolean> {
  const expected = createHmac("sha256", secret)
    .update(payload)
    .digest("hex");
  return `sha256=${expected}` === signature;
}

Teorannú Ráta

Plean Cóid/Lá Iarratais API/Nóim
Free 10 60
Pro 100 300
Business 1,000 1,200
Enterprise Gan teorainn Saincheaptha

Ceanntásca teorann ráta i ngach freagra:

X-RateLimit-Limit: 300
X-RateLimit-Remaining: 247
X-RateLimit-Reset: 1710510060

Formáid Earráide (RFC 7807)

Leanann gach earráid RFC 7807 Problem Details:

{
  "type": "https://docs.qr3.app/errors/validation",
  "title": "Validation Error",
  "status": 422,
  "detail": "url is required for type 'url'",
  "errors": [
    { "field": "url", "message": "Required" }
  ]
}

Conclúid

Tógadh qr3.app ón mbun aníos mar uirlis d'fhorbróirí: REST API oscailte, SDK a chuireann TypeScript ar dtús, CLI, webhooks agus doiciméadúchán iomlán OpenAPI. Féach ar an doiciméadúchán API nó tosaigh sa Deais.