forked from jcrosby/cloudkit
/
rest-api.html
467 lines (401 loc) · 16.4 KB
/
rest-api.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>CloudKit REST API</title>
<link rel="stylesheet" href="main.css" type="text/css" charset="utf-8"/>
</head>
<body>
<div class="wrapper">
<ul class="nav">
<li><a href="rest-api.html" title="REST API">REST API</a></li>
<li><a href="curl.html" title="cURL Tutorial">cURL</a></li>
<li><a href="api" title="RDoc">RDoc</a></li>
<li><a href="http://github.com/jcrosby/cloudkit" title="GitHub Source Repository">Code</a></li>
<li><a href="http://blog.joncrosby.me" title="Author's Blog">Blog</a></li>
</ul>
</div>
<div id="header">
<div class="wrapper">
<h1><a href="index.html">CloudKit</a></h1>
<div class="subpage-subtitle">REST API</div>
</div>
</div>
<div class="meta">
<div class="wrapper">
<p>All request and response bodies are JSON documents.</p>
<p>URI and JSON templates in this document are represented as follows:<br/>
- Values in %% are variables.<br/>
- All other symbols are literals.<br/>
</p>
<p>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.
</p>
<p>All response codes closely follow RFC 2616 with the addition of 422 from
RFC 4918.
</p>
<p>All errors use JSON to supplement their status codes:<br/>
{"error":"%message%"}
</p>
</div>
</div>
<div class="wrapper">
<div class="uri-template">
GET /cloudkit-meta
</div>
<p>
List resource collection URIs hosted at the service root.
</p>
<p>
<span class="spec-header">Response:</span><br/>
{"uris":[%collection-uri-list%]}
</p>
<p>
<span class="spec-header">Response Variables:</span><br/>
<span class="definition">collection-uri-list:</span> an array of collection URIs hosted at the service root.
</p>
<div class="uri-template">
OPTIONS /%uri%
</div>
<p>
Return an Allow header containing the available methods for a given URI.
</p>
<div class="uri-template">
GET /%collection%
</div>
<p>
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.
</p>
<p>
<span class="spec-header">URI Variables:</span><br/>
<span class="definition">collection:</span> a named collection of JSON documents.
</p>
<p>
<span class="spec-header">Optional Query Parameters:</span><br/>
<span class="definition">offset:</span> 0-based starting index for the list of results. Default is 0.<br/>
<span class="definition">limit:</span> maximum number of results to return. Default is undefined, meaning unlimited.
</p>
<p>
<span class="spec-header">Response:</span><br/>
{<br/>
"total":%total-results%,<br/>
"offset":%offset-value%,<br/>
"uris":[%uri-list%]<br/>
}
</p>
<p>
<span class="spec-header">Response Variables:</span><br/>
<span class="definition">total-results:</span> the total number of available results in the complete set, calculated prior applying any provided limits.<br/>
<span class="definition">offset-value:</span> integer representing the offset.<br/>
<span class="definition">uri-list:</span> 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.
</p>
<div class="uri-template">
GET /%collection%/_resolved
</div>
<p>
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.
</p>
<p>
<span class="spec-header">URI Variables:</span><br/>
<span class="definition">collection:</span> a named collection of JSON documents.
</p>
<p>
<span class="spec-header">Optional Query Parameters:</span><br/>
<span class="definition">offset:</span> 0-based starting index for the list of results. Default is 0.<br/>
<span class="definition">limit:</span> maximum number of results to return. Default is undefined, meaning unlimited.
</p>
<p>
<span class="spec-header">Response:</span><br/>
{<br/>
"total":%total-results%,<br/>
"offset":%offset-value%,<br/>
"documents":[%document-list%]<br/>
}
</p>
<p>
<span class="spec-header">Response Variables:</span><br/>
<span class="definition">total-results:</span> the total number of available results in the complete set, calculated prior applying any provided limits.<br/>
<span class="definition">offset-value:</span> integer representing the offset.<br/>
<span class="definition">document-list:</span> 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.
</p>
<p>
<span class="spec-header">Document:</span><br/>
{<br/>
"etag":%etag%,<br/>
"last_modified":%last-modified%,<br/>
"uri":%uri-value%,<br/>
"document":%json-document%<br/>
}
</p>
<p>
<span class="spec-header">Document Variables:</span><br/>
<span class="definition">etag:</span> the value of the ETag normally returned in a response header when requesting the individual document.<br/>
<span class="definition">last-modified:</span> the value of the Last-Modified timestamp normally returned in a response header when requesting the individual document.<br/>
<span class="definition">uri-value:</span> the URI for the individual document relative to the service root.<br/>
<span class="definition">json-document:</span> a valid JSON document.
</p>
<div class="uri-template">
GET /%collection%/%uuid%
</div>
<p>
Return the current version of a JSON document.
</p>
<p>
<span class="spec-header">URI Variables:</span><br/>
<span class="definition">collection:</span> a named collection of documents.<br/>
<span class="definition">uuid:</span> the unique key for a JSON document.
</p>
<p>
<span class="spec-header">Response:</span><br/>
%json-document%
</p>
<p>
<span class="spec-header">Response Variables:</span><br/>
<span class="definition">json-document:</span> a valid JSON document.
</p>
<div class="uri-template">
GET /%collection%/%uuid%/versions
</div>
<p>
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.
</p>
<p>
<span class="spec-header">URI Variables:</span><br/>
<span class="definition">collection:</span> a named collection of JSON documents.<br/>
<span class="definition">uuid:</span> the unique key for a JSON document.
</p>
<p>
<span class="spec-header">Optional Query Parameters:</span><br/>
<span class="definition">offset:</span> 0-based starting index for the list of results. Default is 0.<br/>
<span class="definition">limit:</span> maximum number of results to return. Default is undefined, meaning unlimited.
</p>
<p>
<span class="spec-header">Response:</span><br/>
{<br/>
"total":%total-results%,<br/>
"offset":%offset-value%,<br/>
"uris":[%uri-list%]<br/>
}
</p>
<p>
<span class="spec-header">Response Variables:</span><br/>
<span class="definition">total-results:</span> the total number of available results in the complete set, calculated prior to applying any provided limits.<br/>
<span class="definition">offset-value:</span> integer representing the offset.<br/>
<span class="definition">uri-list:</span> 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.
</p>
<div class="uri-template">
GET /%collection%/%uuid%/versions/_resolved
</div>
<p>
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.
</p>
<p>
<span class="spec-header">URI Variables:</span><br/>
<span class="definition">collection:</span> a named collection of documents.<br/>
<span class="definition">uuid:</span> the unique key for a JSON document.
</p>
<p>
<span class="spec-header">Optional Query Parameters:</span><br/>
<span class="definition">offset:</span> 0-based starting index for the list of results. Default is 0.<br/>
<span class="definition">limit:</span> maximum number of results to return. Default is undefined, meaning unlimited.
</p>
<p>
<span class="spec-header">Response:</span><br/>
{<br/>
"total":%total-results%,<br/>
"offset":%offset-value%,<br/>
"documents":[%document-list%]<br/>
}
</p>
<p>
<span class="spec-header">Response Variables:</span><br/>
<span class="definition">total-results:</span> the total number of available results in the complete set, calculated prior applying any provided limits.<br/>
<span class="definition">offset-value:</span> integer representing the offset.<br/>
<span class="definition">document-list:</span> 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.
</p>
<p>
<span class="spec-header">Document:</span><br/>
{<br/>
"etag":%etag%,<br/>
"last_modified":%last-modified%,<br/>
"uri":%uri-value%,<br/>
"document":%json-document%<br/>
}
</p>
<p>
<span class="spec-header">Document Variables:</span><br/>
<span class="definition">etag:</span> the value of the ETag normally returned in a response header when requesting the individual document.<br/>
<span class="definition">last-modified:</span> the value of the Last-Modified timestamp normally returned in a response header when requesting the individual document.<br/>
<span class="definition">uri-value:</span> the URI for the individual document relative to the service root.<br/>
<span class="definition">json-document:</span> a valid JSON document.
</p>
<div class="uri-template">
GET /%collection%/%uuid%/versions/%etag%
</div>
<p>
Return the given version of a JSON document as specified by its ETag.
</p>
<p>
<span class="spec-header">URI Variables:</span><br/>
<span class="definition">collection:</span> a named collection of documents.<br/>
<span class="definition">uuid:</span> the unique key for a JSON document.<br/>
<span class="definition">etag:</span> the ETag of the desired document version.
</p>
<p>
<span class="spec-header">Response:</span><br/>
%json-document%
</p>
<p>
<span class="spec-header">Response Variables:</span><br/>
<span class="definition">json-document:</span> a valid JSON document.
</p>
<div class="uri-template">
POST /%collection%
</div>
<p>
Create a resource within the given collection using the provided JSON document.
</p>
<p>
<span class="spec-header">URI Variables:</span><br/>
<span class="definition">collection:</span> a named collection of documents.
</p>
<p>
<span class="spec-header">Request Body:</span><br/>
%json-document%
</p>
<p>
<span class="spec-header">Request Body Variables:</span><br/>
<span class="definition">json-document:</span> a valid JSON document.
</p>
<p>
<span class="spec-header">Response:</span><br/>
{<br/>
"ok":true,<br/>
"uri":%uri%,<br/>
"etag":%etag%,<br/>
"last_modified":%last-modified%<br/>
}
</p>
<p>
<span class="spec-header">Response Variables:</span><br/>
<span class="definition">uri:</span> the URI for the stored document relative to the service root.<br/>
<span class="definition">etag:</span> the ETag for the current version of the submitted document.<br/>
<span class="definition">last_modified:</span> 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.
</p>
<p>
<span class="spec-header">Error Response:</span><br/>
{<br/>
"error":%message%<br/>
}
</p>
<p>
<span class="spec-header">Error Response Variables:</span><br/>
<span class="definition">message:</span> a short description of the source of the error.
</p>
<div class="uri-template">
PUT /%collection%/%uuid%
</div>
<p>
Create or update the resource at the given URI.
</p>
<p>
<span class="spec-header">URI Variables:</span><br/>
<span class="definition">collection:</span> a named collection of documents.<br/>
<span class="definition">uuid:</span> the unique key for a JSON document that is being created or updated.
</p>
<p>
<span class="spec-header">Request Body:</span><br/>
%json-document%
</p>
<p>
<span class="spec-header">Request Body Variables:</span><br/>
<span class="definition">json-document:</span> a valid JSON document.
</p>
<p>
<span class="spec-header">Request Headers:</span><br/>
<span class="definition">If-Match:</span> required for documents that are being updated. Ignored for new document storage.
</p>
<p>
<span class="spec-header">Response:</span><br/>
{<br/>
"ok":true,<br/>
"uri":%uri%,<br/>
"etag":%etag%,<br/>
"last_modified":%last-modified%<br/>
}
</p>
<p>
<span class="spec-header">Response Variables:</span><br/>
<span class="definition">uri:</span> the URI for the stored document relative to the service root.<br/>
<span class="definition">etag:</span> the ETag for the current version of the submitted document.<br/>
<span class="definition">last_modified:</span> 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.
</p>
<p>
<span class="spec-header">Error Response:</span><br/>
{<br/>
"error":%message%<br/>
}
</p>
<p>
<span class="spec-header">Error Response Variables:</span><br/>
<span class="definition">message:</span> a short description of the source of the error.
</p>
<div class="uri-template">
DELETE /%collection%/%uuid%
</div>
<p>
Delete the document at the given URI.
</p>
<p>
<span class="spec-header">URI Variables:</span><br/>
<span class="definition">collection:</span> a named collection of documents.<br/>
<span class="definition">uuid:</span> the unique key for a JSON document that is being created or updated.
</p>
<p>
<span class="spec-header">Request Headers:</span><br/>
<span class="definition">If-Match:</span> required for documents that are being updated. Ignored for new document storage.
</p>
<p>
<span class="spec-header">Response:</span><br/>
{<br/>
"ok":true,<br/>
"uri":%uri%,<br/>
"etag":%etag%,<br/>
"last_modified":%last-modified%<br/>
}
</p>
<p>
<span class="spec-header">Response Variables:</span><br/>
<span class="definition">uri:</span> the URI for the stored document relative to the service root. In the case of DELETE, this is the URI for archived resource version.<br/>
<span class="definition">etag:</span> 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.<br/>
<span class="definition">last_modified:</span> 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.
</p>
<p>
<span class="spec-header">Error Response:</span><br/>
{<br/>
"error":%message%<br/>
}
</p>
<p>
<span class="spec-header">Error Response Variables:</span><br/>
<span class="definition">message:</span> a short description of the source of the error.
</p>
<div class="uri-template">
HEAD /%uri%
</div>
<p>
Return the headers for an identical GET at the same URI.
</p>
</div>
</body>
</html>