Skip to content

QR code generator and reader API with Cloudflare Workers

License

Notifications You must be signed in to change notification settings

DavidEredics/qr-re-gen-workers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

qr-re-gen-workers

Deploy to Cloudflare Workers Deploy to Cloudflare Workers GitHub package.json version GitHub

QR code generator and reader API with Cloudflare Workers

This Cloudflare worker can generate QR codes in png and svg format from the text given in A GET or POST request and can read QR codes from a png in a PUT request.

Available routes

path method request Content-Type response Content-Type request example response example
/:text GET text/plain image/svg+xml /example svg example
/:text/:format GET text/plain image/svg+xml, image/png /example/svg svg example
/ POST application/json image/svg+xml, image/png {"text":"example","format":"svg"} svg example
/ PUT image/png application/json png example {"text":"example"}

Generating QR code

GET request

The text that the QR code will generated from must be as the first parameter after the hostname.

Example: the following request will generate a QR code that upon reading will show the text example: [HOSTNAME]/example.

By default the QR code will be in svg format.

image format

To change the format of the image the desired format must be given as a parameter after the text of the QR code. The format can be png or svg.

Example: [HOSTNAME]/example/png

POST request

The Post request must be in json format and contain the text property.

Example: curl 127.0.0.1:8787 -X POST -H "Content-Type: application/json" -d '{"text":"example"}'

By default the QR code will be in svg format.

image format

To change the format of the image the desired format must be given as the format property. The format can be png or svg.

Example: curl 127.0.0.1:8787 -X POST -H "Content-Type: application/json" -d '{"text":"example","format":"png"}'

Reading QR code

A PUT request must be made with the image file, currently only png format supported.

Example: curl --upload-file ..\qr.png 127.0.0.1:8787

The response will be in json format, in case of a successful reading a text property will be returned.

Development

To run it locally you can either use Wrangler or Miniflare

  • Miniflare: Miniflare saved as a devDependency; after npm install the npm run dev command will build with webpack then start a server on localhost and automatically rebuild when a file changes
  • Wrangler: after installing it according to it's docs run wrangler dev

Dependencies

License

MIT

About

QR code generator and reader API with Cloudflare Workers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published