Skip to content

Javascript API

Ignacio del Valle Alles edited this page Mar 12, 2016 · 12 revisions

Brutusin-RPC offers a Javascript-API that facilitates client-side integration.

Main features:

  • Avoids specifying HTTP method.
  • Sends keepalives to maintain HttpSession and Websocket connections open
  • Handles connection errors
  • Includes Spring security CRSF headers obtained from HTML meta tags
  • Eases and optimizes file uploads.
  • Offers high level topic (un)subscription.

Usage:

Include in the header section of the JSP rendering the client-side HTML:

<script src="rpc/brutusin-rpc.js"></script>
<script language='javascript'>
	var http = brutusin["rpc"].initHttpEndpoint("<%=request.getContextPath() + org.brutusin.rpc.RpcConfig.getPath()+"/http"%>");
	var wskt = brutusin["rpc"].initWebsocketEndpoint("<%=request.getContextPath() + org.brutusin.rpc.RpcConfig.getPath()+"/wskt"%>");
</script>

rpcResponse: JSON-RPC response object

http://www.jsonrpc.org/specification#response_object

HTTP API

http.ajax(ajaxParam)

Executes a HTTP service via asynchronous AJAX.

Property Type Description
ajaxParam.service string HTTP service id to execute
ajaxParam.input object HTTP service input object
ajaxParam.files object Associative array. An entry for each property inside input corresponding to a string property with schema format equal to inputstram. The key must much the value of the corresponding input property, and the value is the File object. This API automatically sorts the file parts according to an ascending file length
ajaxParam.load function(rpcResponse) Response callback
ajaxParam.progress function(evt) Progress callback, being ´evt´ of type ProgressEvent

Websocket API

wskt.exec(execParam)

Executes a Websocket service.

execParam has the same properties as ajaxParam except progress and files.

wskt.subscribe(topic, callback)

Subscribes current session to the specified topic.

Property Type Description
topic string Id of the topic to subscribe
callback function(message) Callback function to be executed on arrival of messages. Message structure depends on the topic

wskt.unsubscribe(topic)

Unsubscribes current session from the specified topic.