Fossil

JSON API: Tips and Tricks
Login

(⬑JSON API Index)

Jump to:


Beware of Content-Type and Encoding...

When posting data to fossil, make sure that the request sends:

The response will be (except in the case of an HTTP 500 error or similar) a JSON or JSONP string, ready to be parsed by your favourite JSON.parse() implementation or eval()'d directly.

Using curl and wget

Both curl and wget can be used to post data to this API from the command line or scripts, but both require an extra parameter to set the request encoding.

Example:

$ cat x.json
{
"payload": {
  "sql": "SELECT * FROM reportfmt limit 1",
  "format": "o"
  }
}

# Fossil has been started locally with:
#   fossil server --localauth
# which allows the following requests to work without extra
# authenticaion:

$ wget -q -O- \
  --post-file=x.json \
  --header="Content-Type: application/json" \
  'http://localhost:8080/json/query'

$ curl \
  --data-binary @x.json \
  --header 'Content-Type: application/json' \
  'http://localhost:8080/json/query'

The relevant parts for encoding are the --header flag for wget and curl, noting that they have different syntaxes for each (--header=X vs --header X).

Example JavaScript (Browser and Shell)

In the fossil source tree, in the ajax directory, is test/demo code implemented in HTML+JavaScript. While it is still quite experimental, it demonstrates one approach to creating client-side wrapper APIs for remote Fossil/JSON repositories.

There is some additional JS test code, which uses the Rhino JS engine (i.e. from the console, not the browser), under ajax/i-test. That adds a Rhino-based connection back-end to the AJAJ API and uses it for running integration-style tests against an arbitrary JSON-capable repository.

Demo Apps

Known in-the-wild apps using this API: