Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
api
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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!

About

Sending QR codes via HTTP request in an API project.

Resources

Releases

No releases published

Packages

No packages published