Skip to content
Sending QR codes via HTTP request in an API project.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
api
config
.editorconfig
.gitignore
.sailsrc
README.md
app.js
package.json

README.md

QR example in SailsJS

a Sails application


Description

In this example I show you how to send a QR code via HTTP request in two simple steps:

  1. Add a route to the controller you want to use like
  'GET /qr': 'QrController.index',
  'GET /qr2': 'QrController.showqr'
  1. Require the Node module in the controller, in this case qr-image
  var qr = require('qr-image');

Also you can retreive the data you want to embed in the QR code by the parameters in the request like:

  var text = req.param('data_to_embed');

  var img = qr.image(text);
  res.writeHead(200, {'Content-Type': 'image/png'});
  img.pipe(res);

How to

Just fork or download the repository and enter the folder using cd qr_example and run the following command to install all the dependencies:

  npm install

Then run the following command to execute the Sails project:

  sails lift

Go to http://localhost:1337/qr or http://localhost:1337/qr2 to see the code rendering on the browser or using Postman it will work too.


I hope it could be useful, Follow me on Twitter @Lexynux!

You can’t perform that action at this time.