All request and response bodies are JSON documents.

URI and JSON templates in this document are represented as follows:
- Values in %% are variables.
- All other symbols are literals.

All URIs are relative to the service root, which can be mounted in any number of ways using Rack's URL Maps and Cascades. See the examples directory in the source for specific techniques.

All response codes closely follow RFC 2616 with the addition of 422 from RFC 4918.

All errors use JSON to supplement their status codes:
{"error":"%message%"}

GET /cloudkit-meta

List resource collection URIs hosted at the service root.

Response:
{"uris":[%collection-uri-list%]}

Response Variables:
collection-uri-list: an array of collection URIs hosted at the service root.

OPTIONS /%uri%

Return an Allow header containing the available methods for a given URI.

GET /%collection%

List URIs of available documents within a collection. This includes only current version URIs. Previous versions of a given document are hosted under a different URI. Sort order is descending by last modified date.

URI Variables:
collection: a named collection of JSON documents.

Optional Query Parameters:
offset: 0-based starting index for the list of results. Default is 0.
limit: maximum number of results to return. Default is undefined, meaning unlimited.

Response:
{
"total":%total-results%,
"offset":%offset-value%,
"uris":[%uri-list%]
}

Response Variables:
total-results: the total number of available results in the complete set, calculated prior applying any provided limits.
offset-value: integer representing the offset.
uri-list: an array of document URIs within the given collection. If less than the total available are supplied in the uris element, additional requests can be made, specifying the offset and limit query parameters. Future versions of CloudKit may page result sets to optimize performance.

GET /%collection%/_resolved

List the objects and metadata contained within a collection. This effectively provides the same result as first listing the URIs using GET /%collection% followed by performing a GET /%collection%/%uuid% for each URI.

URI Variables:
collection: a named collection of JSON documents.

Optional Query Parameters:
offset: 0-based starting index for the list of results. Default is 0.
limit: maximum number of results to return. Default is undefined, meaning unlimited.

Response:
{
"total":%total-results%,
"offset":%offset-value%,
"documents":[%document-list%]
}

Response Variables:
total-results: the total number of available results in the complete set, calculated prior applying any provided limits.
offset-value: integer representing the offset.
document-list: an array of documents and their metadata within the given collection. If less than the total available are supplied in the documents element, additional requests can be made, specifying the offset and limit query parameters. Future versions of CloudKit may page result sets to optimize performance.

Document:
{
"etag":%etag%,
"last_modified":%last-modified%,
"uri":%uri-value%,
"document":%json-document%
}

Document Variables:
etag: the value of the ETag normally returned in a response header when requesting the individual document.
last-modified: the value of the Last-Modified timestamp normally returned in a response header when requesting the individual document.
uri-value: the URI for the individual document relative to the service root.
json-document: a valid JSON document.

GET /%collection%/%uuid%

Return the current version of a JSON document.

URI Variables:
collection: a named collection of documents.
uuid: the unique key for a JSON document.

Response:
%json-document%

Response Variables:
json-document: a valid JSON document.

GET /%collection%/%uuid%/versions

List URIs of all versions of a given JSON document. This is a union of current and previous document versions. Sort order is descending by last modified date.

URI Variables:
collection: a named collection of JSON documents.
uuid: the unique key for a JSON document.

Optional Query Parameters:
offset: 0-based starting index for the list of results. Default is 0.
limit: maximum number of results to return. Default is undefined, meaning unlimited.

Response:
{
"total":%total-results%,
"offset":%offset-value%,
"uris":[%uri-list%]
}

Response Variables:
total-results: the total number of available results in the complete set, calculated prior to applying any provided limits.
offset-value: integer representing the offset.
uri-list: an array of document URIs within the given collection. If less than the total available are supplied in the uris element, additional requests can be made, specifying the offset and limit query parameters. Future versions of CloudKit may page result sets to optimize performance.

GET /%collection%/%uuid%/versions/_resolved

List the objects and metadata contained within a collection of document versions. This effectively provides the same result as first listing the URIs using GET /%collection%/%uuid%/versions followed by performing a GET /%collection%/%uuid%/versions/%etag% for each URI.

URI Variables:
collection: a named collection of documents.
uuid: the unique key for a JSON document.

Optional Query Parameters:
offset: 0-based starting index for the list of results. Default is 0.
limit: maximum number of results to return. Default is undefined, meaning unlimited.

Response:
{
"total":%total-results%,
"offset":%offset-value%,
"documents":[%document-list%]
}

Response Variables:
total-results: the total number of available results in the complete set, calculated prior applying any provided limits.
offset-value: integer representing the offset.
document-list: an array of documents and their metadata within the given collection. If less than the total available are supplied in the documents element, additional requests can be made, specifying the offset and limit query parameters. Future versions of CloudKit may page result sets to optimize performance.

Document:
{
"etag":%etag%,
"last_modified":%last-modified%,
"uri":%uri-value%,
"document":%json-document%
}

Document Variables:
etag: the value of the ETag normally returned in a response header when requesting the individual document.
last-modified: the value of the Last-Modified timestamp normally returned in a response header when requesting the individual document.
uri-value: the URI for the individual document relative to the service root.
json-document: a valid JSON document.

GET /%collection%/%uuid%/versions/%etag%

Return the given version of a JSON document as specified by its ETag.

URI Variables:
collection: a named collection of documents.
uuid: the unique key for a JSON document.
etag: the ETag of the desired document version.

Response:
%json-document%

Response Variables:
json-document: a valid JSON document.

POST /%collection%

Create a resource within the given collection using the provided JSON document.

URI Variables:
collection: a named collection of documents.

Request Body:
%json-document%

Request Body Variables:
json-document: a valid JSON document.

Response:
{
"ok":true,
"uri":%uri%,
"etag":%etag%,
"last_modified":%last-modified%
}

Response Variables:
uri: the URI for the stored document relative to the service root.
etag: the ETag for the current version of the submitted document.
last_modified: the Last-Modified timestamp for the submitted document according to the service. This is different from any client last_modified timestamps that may be embedded as a regular part of the JSON document body.

Error Response:
{
"error":%message%
}

Error Response Variables:
message: a short description of the source of the error.

PUT /%collection%/%uuid%

Create or update the resource at the given URI.

URI Variables:
collection: a named collection of documents.
uuid: the unique key for a JSON document that is being created or updated.

Request Body:
%json-document%

Request Body Variables:
json-document: a valid JSON document.

Request Headers:
If-Match: required for documents that are being updated. Ignored for new document storage.

Response:
{
"ok":true,
"uri":%uri%,
"etag":%etag%,
"last_modified":%last-modified%
}

Response Variables:
uri: the URI for the stored document relative to the service root.
etag: the ETag for the current version of the submitted document.
last_modified: the Last-Modified timestamp for the submitted document according to the service. This is different from any client last_modified timestamps that may be embedded as a regular part of the JSON document body.

Error Response:
{
"error":%message%
}

Error Response Variables:
message: a short description of the source of the error.

DELETE /%collection%/%uuid%

Delete the document at the given URI.

URI Variables:
collection: a named collection of documents.
uuid: the unique key for a JSON document that is being created or updated.

Request Headers:
If-Match: required for documents that are being updated. Ignored for new document storage.

Response:
{
"ok":true,
"uri":%uri%,
"etag":%etag%,
"last_modified":%last-modified%
}

Response Variables:
uri: the URI for the stored document relative to the service root. In the case of DELETE, this is the URI for archived resource version.
etag: the ETag for the current version of the document, now archived. This ETag will match the previous version as new ETags are not relevant to deleted resources.
last_modified: the Last-Modified timestamp for the document according to the service. This is different from any client last_modified timestamps that may be embedded as a regular part of the JSON document body. Note that this last_modified timestamp matches the previous version.

Error Response:
{
"error":%message%
}

Error Response Variables:
message: a short description of the source of the error.

HEAD /%uri%

Return the headers for an identical GET at the same URI.