Zebra API Doc

zebra.io.Service Class

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 zebra.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 zebra.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 "zebra.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

Constructor

zebra.io.Service

(
  • url
  • methods
)

Parameters:

  • url String

    an URL of remote service

  • methods Array

    a list of methods names the remote service provides

Item Index

Methods

Attributes

Methods

decode

(
  • name
)
Object protected

Transforms the given remote method response to a JavaScript object.

Parameters:

  • name String

    a remote method name


Return: Object

a result of the remote method calling as a JavaScript object

encode

(
  • name
  • args
)
String protected

Transforms the given remote method execution with the specified parameters to service specific protocol.

Parameters:

  • name String

    a remote method name

  • args Array

    an passed to the remote method arguments


Return: String

a remote service specific encoded string

send

(
  • url
  • data
  • [callback]
)
String protected

Send the given data to the given url and return a response. Callback function can be passed for asynchronous result handling.

Parameters:

  • url String

    an URL

  • data String

    a data to be send

  • [callback] Function optional

    a callback function


Return: String

a result

Attributes

methods

Array readonly

Remote service methods names

url

String readonly

Remote service url