Parsing HTTP request with Photon

Hi,

How do we parse HTTP request that I send from node.js client to Photon TCP server (or the node.js server and Photon as client)?

I want to be able to turn on an LED by sending POST request from node.js to Photon.

On the node.js side:

var request = require('request');
// Configure request
value=100;
var options = {
	url: 'http://192.168.1.41',//Photon's IP address
    method: 'POST',
	headers: {
        'Val': value
    }
}
// Start the request
request(options, function (error, response, body) 
{
    if(!error) 
	{
		var json = JSON.stringify({level: body});
		console.log('Test:'+json)
		return console.log('Server responded with:',body);
    }
	if(error)
	{
		return console.error('ERROR:', error);
	}
})

How do we do “if receive POST, do x” with Photon? I tried with the TCPserver and TCPclient library but it didn’t work

R

You could use HTTPClient or WebServer available as contributed library - or look at their implementation to see how it’s done.