Zebra includes “zebra.io” package where different communication classes and methods are collected.

HTTP POST, GET and other requests

Zebra IO package contains number of handy method to generate GET, POST and other HTTP requests to a remote server. There are two API methods – GET and POST – that help to call remote HTTP server with minimal efforts. The methods support asynchronous and synchronous calls. For instance:

// get data synchronously
var gdata = zebra.io.GET(url),

// post data synchronously    
var pdata = zebra.io.POST(url, "request");

// get data asynchronously
zebra.io.GET(url, function(request) {
    if (request.status == 200) {
    	// handle result
    	request.responseText	
    }
    else { // handle error
       ...
    }
})

Other HTTP methods is supported by more generic IO package class – “zebra.io.HTTP”. The class provides “SEND(httpMethod, url, data, [callback])” method for this purposes. For instance if “PUT” HTTP request is required do it as follow:

  
var http = new zebra.io.HTTP("http://myweb.com");
http.SEND("PUT", "data to be sent");

Communicate to XML-RPC server

// XML-RPC server
var s = new zebra.io.XRPC(url, [ "method1", "method2", "method3" ]);

// call remote methods
s.method1(p1, p2);
var res = s.method2(p2);

// async remote method call
s.method1(p1, p2, function(res) {
    ...
});

Interact to remote JSON-RPC server

// JSON-RPC server
var s = new zebra.io.JRPC(url, [ "method1", "method2", "method3" ]);

// call remote methods
s.method1(p1, p2);
var res = s.method2(p2);

// async remote method call
s.method1(p1, p2, function(res) {
    ...
});

Shortcuts to call remote services

// JSON-RPC remote method execution
var res = zebra.io.JRPC.invoke(url, "method1")(param1, param2);

// Async JSON-RPC remote method execution
zebra.io.JRPC.invoke(url, "method1")(param1, param2, function(res) {
  ....
});