CompleteFTP uses Remote Procedure Calls (RPC) to invoke server-side Javascript from the browser. It does this by automatically generating client-side proxies for calling server-side functions, meaning that adding a remotely invocable server-side function is as easy as adding a client-side function.
Two forms of RPC are supported: JSON-RPC and form-based RPC.
CompleteFTP uses JSON-RPC 2.0 for client-server communications. JSON-RPC is a minimalist JSON-based RPC protocol. For example, the call to the hello() function in the Introduction to JSS is marshalled as
{"jsonrpc": "2.0", "method": "hello", "params": ["world"], "id": 1}
which returns the result in the following form:
{"jsonrpc": "2.0", "result": "Hello world from the server", "id": 1}
Errors are returned as:
{"jsonrpc": "2.0", "error": {"code": 0, "message": "An error occurred"}, "id": 1}
CompleteFTP also supports form-based RPC via standard HTTP GET and POST. If an element named method is included in the form then the Javascript function with that name will be called. The arguments in the call will match the elements in the form - in the same order. Thus the hello() function in the Introduction to JSS may be called by HTTP-POST using the following HTML:
<html>
<body>
<form method=post>
<input type=hidden name=method value=hello>
<input type=text name=firstName>
<input type=submit>
</form>
</body>
</html>
Alternatively it may be invoked by HTTP-GET via the following URL:
http://hostname/directory/script.jss?method=hello&firstName=world
In both these cases the result is returned in the JSON-RPC format, i.e.
{"jsonrpc": "2.0", "result": "Hello world from the server", "id": 1}