qooxdoo-rpc-server

Qooxdoo RPC Server

npm install qooxdoo-rpc-server
6 downloads in the last month

This is a JSON-RPC Server class for the qooxdoo RPC library. The class accept a JSON in the Request body in the following form:

{ "service": "the name of the module" "method": "the name of the method in the module" "params": ["An array containing the parameters passed to the function"] "id": "a sequenze to identify the request answer" }

It returns a JSON-String in the following form:

{ "result": "the result of the querry. Can be every common javascript Type, including arrays or objects" "error": "the error if any. null when everithing is done correctly" "id": "the sequence number if the request" }

usage example:

var http = require("http"); var fs = require ("fs"); var rpc = require("qooxdoo-rpc-server");

var onRequest = function(req, res) { var file = req.url; if (file == "/") { file = "/index.html"; }

var serveFile = function(err, data) {
    if (!err) {
        res.write(data);
    } else {
        res.write(err);
    }
    res.end();
}

var fileExist = function(exist) {
    if (exist) {
        fs.readFile("documents" + file, serveFile);
    } else {
        res.end("File not found.");
    }
}

if (file.search(/^\/api/) != -1) {
    rpc.exec(req, res);

    file = "/index.html";
} else {
    fs.exists("documents" + file, fileExist);
}

}

var onClose = function() { console.log("Server Closed"); }

server = http.createServer();

server.on("request", onRequest); server.on("close", onClose);

server.listen(8080);

npm loves you