JSS API Guide

This document provides an overview of the API available within JSS. Full details are provided in the JSS API Reference.

1. HTTP Request and Response

Access to information about an incoming request is through a global variable called request. It provides information on query-arguments, form-arguments and cookies.

Control of the response is provided through a global variable called response. This variable is usually not required in RPCs where the result may simply be returned from the function. When it is required it is usually to write a response using the write method. Other actions may be to return the contents of a file, which may be done using the downloadFile property, which should be set to the path of the file that is to be returned. If forceDownload if set then the browser will offer the user to save the file rather than attempting to render it. Requests may be redirected to other URLs by setting the redirectUrl property.

2. System

The global variable, system, represents the CompleteFTP system. It provides access to the file-system, authentication and users, databases and information about the current server and site.

3. File-System Access

CompleteFTP's virtual file-system is available via the system.getFile(path) method. This method returns objects of the File class. The fact that an object is returned does not imply that a file exists on that path; this may be checked using the exists() method. Refer to the API reference for more details.

4. Authentication and Users

A script may log users into CompleteFTP using the system.login(userName, password) method. This method does not return anything, but will throw an exception if authentication fails. Once a user has logged in, information about them may be access via the system.user property.

5. Server and Site Information

Information about the current server is available via system.server and about the current site via system.site

6. Database Access

CompleteFTP implements the synchronous part of the Web SQL Database API. Databases may be opened or created using the system.openDatabaseSync(connectionString, version) method. Currently, SQLite, SQL Server Compact, SQL Server, ODBC and OLE DB databases are supported. The first two are embedded databases, which are contained in a single file, so the connection-string to these contain the path to the database-file in CompleteFTP's virtual file-system. For details on connection-strings, refer to the API Reference.

Example: A contact database

An SQLite database containing contacts is created as follows:

var db = system.openDatabaseSync("~/contacts.sqlite", "");
db.transaction(function(tx) {{ '{' }}
	tx.executeSql("CREATE TABLE Contact (ContactID integer PRIMARY KEY, Name text, Phone text);");
{{ '}' }});

A row is inserted as follows:

db.transaction(function(tx) {{ '{' }}
	tx.executeSql("INSERT INTO Contact(Name, Phone) VALUES (?, ?)", ['Joe', '123']);
{{ '}' }});

The code below writes the names and phone numbers of all contacts to the system log:

db.readTransaction(function(tx) {{ '{' }}
	var res = tx.executeSql("SELECT * FROM Contact ORDER BY Name;");
	for (var i=0; i<res.rows.length; i++) {{ '{' }}
		var row = res.rows[i];
		console.log(row.Name + ", " + row.Phone);
	{{ '}' }}
{{ '}' }});

7. Templates

The templating engine makes it easy to separate HTML code from Javascript code. The response global variable provides useful templating methods, which are mirrored in the templater global variable (necessary if response can't be used).

8. Logging

Text may be appended to the CompleteFTP system log using the console.log(message) method. It's logged at the INFO level.