Skip to content
田传武 edited this page Jun 21, 2014 · 3 revisions

The default rest endpoint is http://localhost:1987/store/

Fetch document - GET & HEAD /:docType/:docId

Eg:

$ curl -i 'http://localhost:1987/store/users/larry'
HTTP/1.1 200 OK
Content-Type: application/json

{"v":0, "snapshot":[], "root":{}, "collaborators":[]}

If you just want to know the version, you can send a HEAD request instead of GET.

Get ops - GET /:docType/:docId/_ops?from:FROM&to:TO

Get the operations for the specified document. This returns all operations from versions [FROM,TO). They should both be non-negative numbers. FROM defaults to 0 if not specified. If TO is not specified, all operations from FROM are returned.

The operations are returned as a JSON list.

Eg:

Get all ops in a document:

$ curl 'http://localhost:1987/store/users/larry/_ops'
[{"sid":"sessionId", "uid":"userId", "v":0, "op":[]},
{"sid":"sessionId", "uid":"userId", "v":1, "op":[]},
{"sid":"sessionId", "uid":"userId", "v":2, "op":[]}]

Or you can get just a few operations:

$ curl 'http://localhost:1987/store/users/larry/_ops?from=1&to=3'
[{"sid":"sessionId", "uid":"userId", "v":1, "op":[]},
{"sid":"sessionId", "uid":"userId", "v":2, "op":[]]

Submit Operations - POST /:docType/:docId

You can submit an operation to a document by POST-ing the operation to the document endpoint. The object you post is an opData object. Op data is a JSON object with the following fields:

  • sid: The session ID.
  • uid: The user ID.
  • v: Version of the document to submit against. This should be as recent as possible.
  • op: The operation itself.

The server responce is a JSON object with the following fields:

  • v: The applied version, which is the version at which your operation was applied.
  • ops: A JSON list containing all operations by which your operation was transformed, if any.

You will usually submit operations at the current document version (so, if the document is version 100, you submit an operation with v:100). And normally, the server will apply at the specified version and return an empty ops list. If someone else's operation reaches the server before yours does, your operation will be transformed by theirs, the applied version will be increased and their operation(s) are returned in the reply. See below for an example of this happening.