Purple Robot now includes a local HTTP server that is accessible to local applications on the mobile device. This interface is intended to allow web-based applications built on platforms like PhoneGap or Titanium access to Purple Robot data and functions.

The local web server (when enabled) is accessible via localhost at port 12345:

http://localhost:12345/

This URL will display a placeholder, but an interface for accessing the JSON functionality is available at

http://localhost:12345/test.html

This small page includes a form that allows you to test the JSON command functionality.

The JSON command functionality is exposed via a POST interface located at

http://localhost:12345/json/submit

Data is posted via a standard form with the json field containing text content in the form:

{
    "command": "ping"
}

command is the one required parameter that instructs the server endpoint how to proceed.

The following commands are currently supported:

ping: A small test command that returns a “pong” response.

execute_script: A command that runs JavaScript on the local device. See the Purple Robot JavaScript reference for details about available functionality provided to scripts. The contents of the script are passed via the script parameter:

{
    "command": "execute_script",
    "script": "PurpleRobot.playDefaultTone();"
}

execute_scheme: A command that runs Scheme instructions on the local device. See the Purple Robot scripting reference for details about available functionality provided to scripts. The contents of the script are passed via the source parameter:

{
    "command": "execute_scheme",
    "script": "(begin (pr-play-default-tone) (pr-log "What a great log message!"))"
}

persist_string: A command that stores a string value within Purple Robot:

{
    "command": "persist_string",
    "key": "Hello",
    "value": "Kitty"
}

fetch_string: A command that retrieves a string value stored within Purple Robot:

{
    "command": "fetch_string",
    "key": "Hello"
}

Note that both persist_string and fetch_string support an encrypted keyword that will use protected storage instead of the cleartext storage:

{
    "command": "persist_string",
    "key": "Bow",
    "value": "Wow",
    "encrypted": true
}

{
    "command": "fetch_string",
    "key": "Bow",
    "encrypted": true
}