Skip to content

Instantly share code, notes, and snippets.

@k33g
Created January 23, 2011 04:17
Show Gist options
  • Save k33g/791813 to your computer and use it in GitHub Desktop.
Save k33g/791813 to your computer and use it in GitHub Desktop.
"json service" with node.js
var
sys = require('sys'),
http = require('http');
function myservice(){/*return objects*/}
http.createServer(function (req, res) {
/* url to call service :
http://localhost:3000/woman:lara:croft
*/
var
parts = req.url.split("/"),
params = parts[1].split(":"),
result = myservice(params);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(""+JSON.stringify(result));
}).listen(3000, "127.0.0.1");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment