sending GET/POST responses

20 views
Skip to first unread message

Gerald Yeo

unread,
Aug 14, 2012, 9:15:41 PM8/14/12
to flati...@googlegroups.com
Hi group,

I'm new to node and flatiron.

I'm trying to use flatiron to create an app that uses Instagram's realtime api. So the first step is to handle the subscription, and I'm stumbling on sending back the hub.challenge response.

I tried looking at the examples in GitHub, the closes that I can get is the app.res.json function.

Can anyone point me in the right direction, either to documentation or examples?

Here's my starting app...

var flatiron = require('flatiron'),
    qs = require('qs');

// declarations
var instagramClientId = 'ID',
    instagramClientSecret = 'SECRET',
    app = flatiron.app;

app.use(flatiron.plugins.http);

app.router.configure({ 'strict':false });

//----- routes --------------------------------------------------
// index
app.router.get('/', function () {
    this.res.writeHead(200, {'content-type':'text/plain'});
    this.res.end('index');
});

// callback
app.router.path('/callback', function () {
    // GET /callback
    // If param hub.challenge is present, renders its value
    // This URL is used by subscription system of Instagram
    // to check if the callback URL provided when creating the subscription
    // is valid and works fine
    this.get(function () {
        if (this.req.query['hub.challenge'] != null) {
            //this.res.send(this.req.query['hub.challenge']);
            console.log(this.res)
        }
        else {
            app.log.info("ERROR on subscription request: %s");
        }
    });

    // post
    this.post(function () {
        // @todo
        this.res.writeHead(200, { 'content-type':'text/plain' });
        this.res.end('hello!');
    });
});

// start the server
app.start(8080, function (err) {
    if (err) {
        throw err;
    }

    var addr = app.server.address();
    app.log.info('listening on http://' + addr.address + ':' + addr.port);
});

Gerald Yeo

unread,
Aug 14, 2012, 10:52:47 PM8/14/12
to flati...@googlegroups.com
ok, so I may have solved my own problem :)

Basically this two lines did it...
this.res.writeHead(200, { 'content-type':'text/plain' });
this.res.end(this.req.query['hub.challenge']); 


Reply all
Reply to author
Forward
0 new messages