Skip to content

Instantly share code, notes, and snippets.

@navinthenapster
Last active January 1, 2018 08:23

Revisions

  1. Navin Infant Raj renamed this gist Jan 1, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Navin Infant Raj created this gist Jan 1, 2018.
    49 changes: 49 additions & 0 deletions sample controller
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@

    //GET PARAMETER IN url query (www.google.com?search='hi')
    exports.weather = function (req, res) {

    res.setHeader("Access-Control-Allow-Origin", "*");
    res.setHeader('Content-Type', 'application/json');

    var place= req.query.q;
    //API Config
    var url='http://ipapi.co/json';
    var request= require('request');
    request(url,function(err,response,body){
    if(err)
    res.end(JSON.stringify({code:500, message:"Could not find weather "}));

    res.end(body);
    });
    };

    //GETTING PARAMETER IN URL / (http://localhost:8080/view/2309)
    exports.block = function (request, response) {



    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader('Content-Type', 'application/json');

    var data = request.params.index;

    response.end(JSON.stringify({ block: web3.eth.getBlock(data) }));

    };

    //GETTING PARAMETER IN POST in body parser ( body parser must be include in server.js )
    exports.new_product = function (request, response) {

    console.log(request.body)

    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader('Content-Type', 'application/json');


    var data = request.body;
    console.log(data.IMEI);
    response.end(JSON.stringify({ status: true ,code:200 ,message : "data received", data:request.body }))

    };