Ayush
Ayush
May 9 · 5 min read

Generate QR codes by just passing a text in Query Parameters.

Photo by Mitya Ivanov on Unsplash

In this blog post we will see how I used QR Codes till now.

  • Learn how Azure Functions can be a lego piece in your Architecture and Business.
  • No spoilers of Game of Thrones, feel free to read every part ;p
  • Enable images pls.

tl;dr

1. QRcode.js — Quick Response Codes

2. RasteriseHTML — Downloadable Image

3. Read text from Query Parameter, and send QR code in Response.

Didn’t understand? Fallthrough the blog.

QR code?

I think QR code as a gateway to from the “real world” to the “internet”.
We see QR Codes being used in many ways, in movie/event tickets, in Payments, WIFI network login etc.

But what’s a blog on QR without it’s full form right?
It’s known as Quick Response Code.

QChain - QR Enabled Keychain

We made QChain in an Experiment which was startup for a Week. We thought of an idea in 12 Hours and Executed it whole week long.

Qchain gives you hope of finding lost key by just having a QR with the useful information of the owner.

To gather customers we generated funds by Crowdfunding and started Delivering their Product after a Week.

We used to 3D print the case and Print the QR code on a Sticker Page, cut it and Paste it on the Case. We couldn’t Automate the hardware, but the Software, ofcourse I had Azure functions.

In form where people used to Pay us and Submit their information, I sent the submission to QRFn to generate their QR’s on the event(awesome r8).

Moreover when I Built Cliniq , I used QRfn while building the service for patients to book appointments. The idea behind Cliniq was to skip long waiting queues to see the doctor.

Patient portal can generate QR code with a Primary Key used in our database and can have an appointment book with a scheduled time.

Doctors can Scan the QR and write Symptoms, notes and Prescription in the fields. Doctor portal justs inserts the data using primary key in the QChain.

Similarly the Chemists can Scan the QR and retrieve Precription and provide medicines, using the primary key.

QRfn was found essential and delivering.

Azure Functions

Azure Functions is a serverless compute service that enables you to run code on-demand without having to explicitly provision or manage infrastructure. We can Use Azure Functions to run a script or piece of code in response to a variety of events.

Azure function is easy to imagine as a Lego, a piece which helps build a building or a ship with the elephants. It can serve as crucial API to all your Stack needs when there isn’t any existing API for the same.

Also this Lego piece can be a Ship alone, Performative and you don’t need to pay till you use it (pay per execution model).

Ohkay now, Let’s get Started with QRfn

You can also use and copy paste the code from github repo as images won’t let you ;p https://github.com/heyayushh/qrfn

1. Write HTML to Respond with a Template

Requiring Stuff in <head>

  • QRCode.js — To make QR code
  • rasterizeHTML — To make a Image out of HTML
Another place for my <head>. RIP linkin park.

<body> of the HTML

The div placeholder will be holding the king of the throne( QR code here ). Screen is just a container for placeholder. Also I added A download button which executes a script named download() on click, which will download the file.

Being sexy is something inside, not every <body> has it.

Scripts

You won’t find it in half of bollywood movies.

This generates a QR Code in the HTML tag.
You can read more about QRCode.js here.

convert HTML to a JS String

As we are sending client a HTML page from JS we should convert it. As the html content contains lots of ‘,”,< , the js will give errors of parsing, and either we have to use escape characters or use this code.

Mention the path and filename correctly.

In mac OS/ Linux run the command in the directory same as the HTML Page. or you can also copy-paste the console output too.

node convertHtmlToString.js | cat >> var.txt

Now, Save the content of var.txt/output for later use.

Azure Functions

Requirements

  • Azure Portal

1. Create a Function App

1 Step — Create an a Azure function App

2. Use in-portal development

step — 2 Use in-portal Development

3. Create a HTTP trigger/ Webhook / API function

Step 3 — Create a function

4. It’s the showtime.

Step 4 — Write the code.
CODE 😍

The code has so much to say, merely 10 lines.

qrSite is the variable with the html code we saved earlier.

genQr(text) function returns a QR of the text passed earlier as an argument(same like my girlfriend).

context.res is the response body(json) for azure function of a successful request.

Save and run the code either in test section or postman adding the text as mentioned below:

https://<yourFunctionApp>.azurewebsites.net/api/<yourFunctionName>?text=thanku4ReadingMyBlogLolplsclap

and it will respond with a HTML website with a QRcode generator.

There we go, we have king of seven kingdoms, protector of the WiFi password, QRfn.



This is the code to QRfn, May the force be with you.

A tip for everyone : Please have breakfast everyday despite your busy life.

Microsoft Azure

Any language. Any platform. Our team is focused on making the world more amazing for developers and IT operations communities with the best that Microsoft Azure can provide. If you want to contribute in this journey with us, contact us at medium@microsoft.com

Ayush

Written by

Ayush

Copy-Pasta or Copy-Sphegatti idk. https://heyayush.dev/

Microsoft Azure

Any language. Any platform. Our team is focused on making the world more amazing for developers and IT operations communities with the best that Microsoft Azure can provide. If you want to contribute in this journey with us, contact us at medium@microsoft.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade