Algobook
- The developer's handbook
mode-switch
back-button
Buy Me A Coffee

QR code API

API for creating and decoding QR-codes. Choose to create the QR code as either a SVG or a PNG image, and also which size you want it to be. The API also supports decoding of an image of a QR code.

Documentation

The API consists of two endpoints as of today

GET https://api.algobook.info/v1/qr/create?data=QR code value&format={format}&width={width} POST https://api.algobook.info/v1/qr/verify body: file

Examples

Below we will show some example of how the API can be used in JavaScript and HTML

GET /qr/create (PNG)

The only mandatory parameter is the data param. Default format will be png and default width will be 200, but they can be provided to fit the consumers needs.

<img src="https://api.algobook.info/v1/qr/create?data=QR code value" />

Above code will render a PNG image of the QR code in the <img>.

GET /qr/create (SVG)

To get a SVG representation of the QR, provide the format param as SVG

const response = await fetch( "https://api.algobook.info/v1/qr/create?data=QR code value&format=svg" ); const svg = await response.text(); console.log(svg);

Response

<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 33 33" shape-rendering="crispEdges"><path fill="#ffffff" d="M0 0h33v33H0z"/><path stroke="#000000" d="M4 4.5h7m1 0h2m3 0h1m1 0h1m2 0h7M4 5.5h1m5 0h1m2 0h4m1 0h1m3 0h1m5 0h1M4 6.5h1m1 0h3m1 0h1m1 0h1m2 0h2m1 0h2m2 0h1m1 0h3m1 0h1M4 7.5h1m1 0h3m1 0h1m2 0h1m1 0h2m1 0h3m1 0h1m1 0h3m1 0h1M4 8.5h1m1 0h3m1 0h1m1 0h1m1 0h1m1 0h2m1 0h1m2 0h1m1 0h3m1 0h1M4 9.5h1m5 0h1m3 0h2m3 0h2m1 0h1m5 0h1M4 10.5h7m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h7M12 11.5h5m1 0h1M9 12.5h2m2 0h2m4 0h1m2 0h1m1 0h1m1 0h1m1 0h1M6 13.5h1m1 0h2m4 0h1m1 0h3m4 0h2m1 0h1M5 14.5h3m2 0h1m2 0h3m1 0h2m3 0h1m1 0h2m2 0h1M6 15.5h1m1 0h1m3 0h1m1 0h2m4 0h4m1 0h1M5 16.5h2m1 0h6m1 0h1m1 0h1m2 0h1m1 0h1m2 0h1m1 0h2M4 17.5h2m1 0h2m3 0h3m3 0h1m1 0h1m2 0h1m3 0h2M4 18.5h1m2 0h2m1 0h2m1 0h1m1 0h1m5 0h1m4 0h3M4 19.5h1m1 0h2m1 0h1m1 0h1m2 0h1m1 0h1m2 0h1m2 0h1m1 0h5M4 20.5h1m1 0h1m3 0h1m1 0h1m2 0h3m2 0h7m1 0h1M12 21.5h1m1 0h2m1 0h2m1 0h1m3 0h5M4 22.5h7m5 0h1m2 0h2m1 0h1m1 0h1m3 0h1M4 23.5h1m5 0h1m1 0h2m1 0h3m2 0h1m3 0h2m1 0h2M4 24.5h1m1 0h3m1 0h1m3 0h1m1 0h1m2 0h9M4 25.5h1m1 0h3m1 0h1m3 0h1m2 0h6m2 0h2m1 0h1M4 26.5h1m1 0h3m1 0h1m2 0h1m1 0h4m2 0h1m3 0h1m2 0h1M4 27.5h1m5 0h1m3 0h1m1 0h1m1 0h1m1 0h4m1 0h1m2 0h1M4 28.5h7m2 0h2m1 0h3m1 0h1m1 0h1m1 0h2m2 0h1"/></svg>

POST /qr/verify

In order to verify and decode the QR code image, we can use the API as follows

import qr from "./qr.png"; const base64ToBlob = (base64: string) => { const byteCharacters = window.atob(base64); const byteNumbers = new Array(byteCharacters.length); for (let i = 0; i < byteCharacters.length; i++) { byteNumbers[i] = byteCharacters.charCodeAt(i); } const byteArray = new Uint8Array(byteNumbers); return new Blob([byteArray]); }; const formData = new FormData(); formData.append("file", base64ToBlob(qr.split(",")[1])); const response = await fetch("https://api.algobook.info/v1/qr/verify", { method: "POST", body: formData, }); const data = await response.json(); console.log(data);

Response

{ "decodedValue": "Value of QR" }

Feedback

Do you have any feedback or think something can be improved? We love to hear from you, contact us here.

signature
See all our articlesSee all our open source projects