Class zebkit.io.Service | <zebkit.io> |
A remote service connector class. It is supposed the class has to be extended with different protocols like RPC, JSON etc. The typical pattern of connecting to a remote service is shown below:
// create service connector that has two methods "a()" and "b(param1)"
var service = new zebkit.io.Service("http://myservice.com", [
"a", "b"
]);
// call the methods of the remote service
service.a();
service.b(10);
Also the methods of a remote service can be called asynchronously. In this case a callback method has to be passed as the last argument of called remote methods:
// create service connector that has two methods "a()" and "b(param1)"
var service = new zebkit.io.Service("http://myservice.com", [
"a", "b"
]);
// call "b" method from the remote service asynchronously
service.b(10, function(res) {
// handle a result of the remote method execution here
...
});
Ideally any specific remote service extension of "zebkit.io.Service" class has to implement two methods:
- **encode** to say how the given remote method with passed parameters have
to be transformed into a concrete service side protocol (JSON, XML, etc)
- **decode** to say how the specific service response has to be converted into
JavaScript object
zebkit.io.Service
(url, methods
)
Parameters:
protected
|
<Object> | decode (name) |
protected
|
<String> | encode (name, args) |
private
static
|
<Function> | invoke (clazz, url, a) |
protected
|
<zebkit.DoIt> | send (url, data) |
private
static
<Function>
invoke (clazz, url, a )
Build invoke method that calls a service method. Parameters:
Returns:
<Function>
a wrapped method to call RPC method with |
protected
<zebkit.DoIt>
send (url, data )
Send the given data to the given url and return a response. Callback function can be passed for asynchronous result handling. Parameters:
Returns:
<zebkit.DoIt>
a result |