API Reference

This is a reference for the API that will be in versions 0.4.5 and above. The code currently resides in the xmlapi branch on git. It is not intended to be comprehensive. Instead, it is intended to provide examples for how to do common tasks.

Important note about HTTP methods: Because of a bug/feature in eXist, the API can't use HTTP PUT or HTTP DELETE directly. Instead, when an API call says PUT or DELETE, you MUST use HTTP POST and provide an additional HTTP header: X-HTTP-Method-Override: [real method]

Most APIs will return HTML service discovery information if called with HTTP GET with the Accept header is "application/xhtml+html"

Most APIs will run their test suites and report results if called with HTTP GET and query parameter ?_test=1 (or ?_test=[test path]). APIs that support testing will indicate it in one or more html:link elements in the html:head section of their service discovery calls.

=Authentication=

Two forms of authentication are allowed:
 * Session-based authentication: use the login and logout APIs, pass the session cookie with each transaction
 * HTTP Basic authentication: pass the standard HTTP Basic headers with each transaction, no login/logout required

Many APIs require authentication, but the authentication information is not shown in the examples.

=Data format=

Many of the APIs support more than one data format. Common data formats by MIME type are:


 * text/plain
 * Plain UTF-8 encoded text with no markup


 * application/xhtml+xml, text/html
 * XHTML. HTTP GET in HTML mode usually returns the service discovery page.


 * application/xml
 * XML data, which may or may not be TEI.


 * application/tei+xml
 * TEI fragments or a complete TEI document.


 * application/x-www-form-urlencoded
 * URL-encoded key-value pairs, as commonly sent by HTML forms.

To specify that data should be received in a given format, put the MIME type in the Accept header of the HTTP GET request. If the API can't send data in the specified format, it will return HTTP status code 406.

To specify that data is being sent in a given format, put the MIME type in the Content-type header of the HTTP POST request.

The default format is usually application/xhtml+xml

The service discovery mode (usually obtained through HTTP GET in XHTML format) will tell you what data formats are supported by its subordinate APIs.

=HTTP return codes=

The API uses consistent HTTP status codes to indicate success or failure.

Success codes

 * 200 OK
 * the transaction completed successfully and there is data returned


 * 201 Created
 * the transaction completed successfully and created a new object. The Location header may contain the object's URI.


 * 202 Accepted
 * the transaction completed successfully, but the action will be performed in the background


 * 204 No content
 * the transaction completed successfully, but there is nothing to return

Failure codes

 * 400 Bad request
 * Something is wrong with the data that was sent. Usually accompanied by an error message.


 * 401 Authorization required
 * The requested transaction requires log in, but you are not logged in


 * 403 Forbidden
 * The requested transaction requires log in with specific credentials, but you don't have them


 * 404 Not found
 * The API cannot be found or the requested document is inaccessible to you


 * 406 Unacceptable
 * The Accept header requests a specific return content type, but the API can't serve it


 * 500 Internal error
 * Something went wrong in the server. Usually indicates a bug, bad hardware, low memory, or the like.

=Data model=

The data model of an Open Siddur document consists of the following main sections:


 * Text repository
 * stores short segments of text as tei:seg elements, referencable by @xml:id. The repository is an unordered list.


 * Selection
 * An ordered list of tei:ptr elements, referencable by @xml:id that point into the document's text repository or to concurrent hierarchies in other documents.


 * Views
 * Each view imposes one type of hierarchical order on the elements of the selection. It consists of hierarchically ordered elements (examples: tei:p, tei:s, tei:div, tei:ab, tei:lg, tei:l) that, at the lowest level, contain pointers (tei:ptr elements) that point into the selection.


 * Concurrent hierarchies
 * A selection and a set of views comprises one set of concurrent hierarchies.

=User management=

Log in
Once logged in, a session cookie keeps track of the logged in user. You must transmit the session cookie along with all future requests. Login sessions expire after 20 minutes of inactivity.

Get profile properties
Supported profile properties are name, email, and orgname (affiliation to an organization).

Set profile properties
=Data API=

Create a new document
New documents can be created two ways:
 * Post a main title (as below). The new document will contain a blank JLPTEI template.
 * Post an entire valid JLPTEI document

The API-accessible location of the document will be returned in the Location header.

Remove a document
Note: If you try to remove a document that other documents to which other documents make reference, you will get an HTTP 400 error. The object will be a list of all documents where the references are.

=Search API=


 * Search-capable API calls all use the same parameter set.
 * Search capability can be found by calling the service discovery API and checking for an html:link to the search description.
 * The search API will never return results from inaccessible documents.

Common parameters
A basic search involves calling an API with the query parameter ?q=query Additional parameters are:


 * start=n
 * Start the list from result n (an integer)


 * max-results=n
 * Return no more than n results per page


 * owner=user
 * List only results that are in documents owned by user


 * group=group
 * List only results that are in documents owned by group

Find all text segments containing a string
=Compilation API=