Simple REST service to generate a QR codes
Based on "How to Generate a QR Code with Go" tutorial on the Twilio blog.
To install and test this service, you will need:
- Golang installed locally
- OpenSSL to generate self-signed certificates (public and private keys)
- Curl CLI app
- A smartphone with a QR code scanner
To start the service, run the following commands:
- Build the service
go build -o genqr genqr.go
cmod 755 genqr
- Generate self-signed certificates
openssl req -x509 -noenc -days 365 -newkey rsa:2048 -keyout certs/server.key -out certs/server.crt
- Run the service
./genqr -port=8080 -cert=certs/server.crt -key=certs/server.key
To generate a QR code, send a POST request to http://localhost:8080/ with two POST variables:
- size: This sets the width and height of the QR code
- content: This is the content that the QR code will embed
The curl example, below, shows how to create a QR code 256x256 px that embeds "https://google.com", and outputs the generated QR code to data/qrcode.png.
curl -X POST \
--form "size=256" \
--form "content=https://google.com" \
--output data/qrcode.png \
https://localhost:8080/
Open the data/qrcode.png in your image viewer to see the QR code. Scan the QR code with the QR code scanner on your smartphone and see the content embedded in the QR code.