Skip to content

Instantly share code, notes, and snippets.

@jcrosby
Created January 10, 2009 00:24
Show Gist options
  • Save jcrosby/45327 to your computer and use it in GitHub Desktop.
Save jcrosby/45327 to your computer and use it in GitHub Desktop.
# The CloudKit 0.9.x way to list resources in a collection --
# Still valid and useful...
$ curl -i http://localhost:9292/notes
HTTP/1.1 200 OK
Last-Modified: Sat, 10 Jan 2009 00:12:52 GMT
ETag: "c01f6230a8c40a2576b6f35f32f966ab"
Link: <http://localhost:9292/notes/_resolved>; rel="http://joncrosby.me/cloudkit/1.0/rel/resolved"
Cache-Control: proxy-revalidate
Content-Type: application/json
Content-Length: 63
{
"uris":[
"\/notes\/apple",
"\/notes\/foo"
],
"offset":0,
"total":2
}
# Now, in 0.10.0, there is also (as hinted in the Link header
# above) a resolved form of this content, equivalent to
# first listing the URIs (as above), followed by fetching
# each resource individually. While fetching resources
# individually works fine in small quantities, it is O(n)
# and doesn't scale well to larger numbers of documents...
$ curl -i http://localhost:9292/notes/_resolved
HTTP/1.1 200 OK
Last-Modified: Sat, 10 Jan 2009 00:12:52 GMT
ETag: "2b1dbdbc66b54980867c530dec62ef1e"
Link: <http://localhost:9292/notes>; rel="index"
Cache-Control: proxy-revalidate
Content-Type: application/json
Content-Length: 338
{
"documents":[
{
"document":"{\"color\":\"green\"}",
"etag":"586a6cf0-c0d9-012b-a573-0017f2c62348",
"last_modified":"Sat, 10 Jan 2009 00:12:52 GMT",
"uri":"\/notes\/apple"
},
{
"document":"{\"foo\":\"bar\"}",
"etag":"40e5e680-c0d9-012b-a573-0017f2c62348",
"last_modified":"Sat, 10 Jan 2009 00:12:12 GMT",
"uri":"\/notes\/foo"
}
],
"offset":0,
"total":2
}
# Notice the response contained a Link header pointing back
# to its own index.
# This same "_resolved" technique works for version history
# collections too...
$ curl -i http://localhost:9292/notes/foo/versions/_resolved
HTTP/1.1 200 OK
Last-Modified: Sat, 10 Jan 2009 00:21:25 GMT
ETag: "5e014eee93954cf9c8052378e7cd45fc"
Link: <http://localhost:9292/notes/foo/versions>; rel="index"
Cache-Control: proxy-revalidate
Content-Type: application/json
Content-Length: 380
{
"documents":[
{
"document":"{\"foo\":\"baz\"}",
"etag":"8a8333f0-c0da-012b-a573-0017f2c62348",
"last_modified":"Sat, 10 Jan 2009 00:21:25 GMT",
"uri":"\/notes\/foo"
},
{
"document":"{\"foo\":\"bar\"}",
"etag":"40e5e680-c0d9-012b-a573-0017f2c62348",
"last_modified":"Sat, 10 Jan 2009 00:12:12 GMT",
"uri":"\/notes\/foo\/versions\/40e5e680-c0d9-012b-a573-0017f2c62348"
}
],
"offset":0,
"total":2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment