Introduction
In the past few months, I have come to realise that a lot of functionality that you need as a developer is already available (in some form or the other) on the Internet. There is no point of reinventing the wheel and more time should be spent on designing the overall logic, the "Whats" of the program rather than the "Hows".
API: What's the fuss about?
Let's start by understanding what an API is. Formally, an Application Programming Interface or an API is a set of functions and procedures that allow the creation of applications which access the features or data of an operating system, application, or other service. In simple words, an API is a method by which a piece of software or code can interact with another software.
Say, for instance, someone wrote an awesome code for one specific task and you, as a developer, want that feature to be incorporated in your app. You can build that feature from scratch, implementing the lower-level details of that feature. But, that won't do much good as it will be time consuming and little good will come out of it. After all, it was just a feature in the larger app, a piece in the bigger picture, right?
Another better way would be to use an already existing API. Someone spent a lot of time on that specific feature so that other developers like you can use it with ease and spend more time on other important details. If some day, you come up with something that you think can be reused, create an API for it!
The QR Code API
A lot of APIs are available open source on the internet, meaning that you can read their source code, understand them and incorporate them in you own application/website. One such API is the Quick Response or QR Code API provided by goqr.me. It allows you to create custom qr codes images that can be scanned by any device that supports this technology. You can even create colored qr codes or get them printed on your t-shirt, mug, visiting card and what not!
How does it work?
What happens is, we create a QR Code image by providing a url or some data. A unique qr image is created for that url or data. Whenever a device scans the code, it extracts the data which was used to create the code. The data can then be used for any purpose, such as to redirect the user to a particular website, installation page of an app etc. The data can also be used to log in a user or do some other interesting stuff.
First of all, we create a sample qr code image by going to the url:
https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=Example
The data=Example is the most important part. Different values of data will give different qr codes, and same qr code will be generated each time for some data. Now, you can download any qr code reader app on your smartphone.
When you scan the image, it will show the data (Example here). Change Example to something else, like your name and it will generate a different image.

The size=150x150 parameter is optional. The size should be a square one. If not specified or incorrect format is used, it will use 200x200 pixels by default.
The image is in png format by default, but you can create the qr code image in other formats such as svg. There are other options as well, which can be applied to the image.
Reading QR code
To read back the data from image, just go to the url:
http://api.qrserver.com/v1/read-qr-code/?fileurl=http%3A%2F%2Fapi.qrserver.com%2Fv1%2Fcreate-qr-code%2F%3Fdata%3DHelloWorld
It will return a JSON response that will be something like:
[{"type":"qrcode","symbol":[{"seq":0,"data":"HelloWorld","error":null}]}]
Some use cases of qr code can be:
=>For attendance of users in an office. You can generate a new qr code at regular intervals (say ten seconds) using some pseudo-random data on a fixed device at the office. The users will scan the image on their devices and the data from the last qr code can be used to mark an attendance.
=>You can even use qr codes to allow users to view an ad, and based on that, provide coupon codes for discounts on an e-commerce website.
That's it for now! Read more about the api at:
http://goqr.me/api/
No comments:
Post a Comment