cson_cgi

Not logged in

ACHTUNG: THIS PAGE IS NOW MAINTAINED IN THE NEW WIKI: http://whiki.wanderinghorse.net/wikis/cson/?page=cson_cgi

See also: cson_cgi_HowTo, cson_session

Online demo: http://fossil.wanderinghorse.net/demos/cson/

cson_cgi

cson_cgi is an experimental mini-framework, based off of cson, for creating JSON-only CGI web applications. The library imports various CGI-related data (e.g. environment variables, GET/POST data) into JSON form, makes it available to the client application, and handles the output of generated JSON. Client applications are intended to generate only JSON as output, and need only work with high-level cson objects. This library handles all i/o and parsing.

It is primarily intended for implementing JSON-centric AJAX-based back-ends. It can also be used for writing JSON-centric apps which are not necessarily CGI-specific. The library itself does not require a CGI-like environment to run, but without CGI-based input some of its functionality will be missing (e.g., it obviously cannot manage inbound HTTP POST data if there is no associated POST request).

cson_cgi provides an easy-to-use basis for writing CGI applications which themselves produce only JSON data. It is not intended for writing HTML-generating CGIs, and its output model will not work with such applications. That said, it can be used in conjunction with such applications as long as the client takes over the generation of all output (but the library can still be helpful in processing incoming GET/POST data and provide persistent session state).

What currently works:

Notable TODOs...

Less significant TODOs...

Things it won't ever do...

Sample output

Here's some sample client application output. This app simply returns some of the various cson_cgi environment data to the user...

{
    "argv": [
        "./cgi-test",
        "-a=b",
        "c",
        "123"
    ],
    "$ENV": {
        "GATEWAY_INTERFACE": "CGI/1.1",
        "CONTENT_TYPE": "application/json",
        "HTTP_ACCEPT_CHARSET": "ISO-8859-1,utf-8;q=0.7,*;q=0.3",
        "HTTP_X_REQUESTED_WITH": "XMLHttpRequest",
        "REMOTE_ADDR": "127.1.1.1",
        "QUERY_STRING": "a[]=3&a[]=7",
        "REMOTE_PORT": "43422",
        "DOCUMENT_ROOT": "/home/stephan/cvs/fossil/cson",
        "HTTP_USER_AGENT": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.28 (KHTML, like Gecko) Chrome/12.0.725.0 Safari/534.28",
        "SERVER_SIGNATURE": "<address>Apache/2.2.16 (Ubuntu) Server at cson-cgi Port 80</address>\n",
        "HTTP_ACCEPT": "application/json, text/javascript, */*",
        "CONTENT_LENGTH": "39",
        "SCRIPT_FILENAME": "/home/stephan/cvs/fossil/cson/index.cgi",
        "HTTP_HOST": "cson-cgi",
        "REQUEST_URI": "/index.cgi?a[]=3&a[]=7",
        "SERVER_SOFTWARE": "Apache/2.2.16 (Ubuntu)",
        "HTTP_CONNECTION": "keep-alive",
        "HTTP_COOKIE": "cson_session_id=39063eee%2D7e34%2D649f%2Ddfed%2D1cfd2c6a452f",
        "PATH": "/usr/local/bin:/usr/bin:/bin",
        "HTTP_ACCEPT_LANGUAGE": "en-US,en;q=0.8",
        "HTTP_REFERER": "http://cson-cgi/demo.html",
        "SERVER_PROTOCOL": "HTTP/1.1",
        "HTTP_ACCEPT_ENCODING": "gzip,deflate,sdch",
        "REQUEST_METHOD": "POST",
        "SERVER_ADMIN": "[no address given]",
        "SERVER_ADDR": "127.1.1.1",
        "PWD": "/home/stephan/cvs/fossil/cson",
        "HTTP_ORIGIN": "http://cson-cgi",
        "SERVER_PORT": "80",
        "SCRIPT_NAME": "/index.cgi",
        "SERVER_NAME": "cson-cgi"
    },
    "$GET": {
        "a": [
            "3",
            "7"
        ]
    },
    "$COOKIE": {
        "cson_session_id": {
            "expires": 1303235938,
            "value": "39063eee-7e34-649f-dfed-1cfd2c6a452f"
        }
    },
    "$POST": {
        "hi": "world",
        "demotime": "now"
    },
    "$APP": {
        "guessedOutputContentType": "application/json",
        "timestamp": 1302631138
    },
    "$SESSION": {
        "timestamp": 1302631138,
        "hits": 14,
        "sessionManager": "sqlite3"
    }
}