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.
path | method | request Content-Type | response Content-Type | request example | response example |
---|---|---|---|---|---|
/:text | GET | text/plain | image/svg+xml | /example | |
/:text/:format | GET | text/plain | image/svg+xml, image/png | /example/svg | |
/ | POST | application/json | image/svg+xml, image/png | {"text":"example","format":"svg"} | |
/ | PUT | image/png | application/json | {"text":"example"} |
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.
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
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.
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"}'
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.