Skip to content

Instantly share code, notes, and snippets.

View mamund's full-sized avatar

Mike Amundsen mamund

View GitHub Profile
@mamund
mamund / gist:5782198
Created June 14, 2013 14:22
Adding "object" with metadata wrapper to Collection+JSON
// sample links array
{
"collection" :
{
"version" : "1.0",
"href" : URI,
"items" :
[
{
"href" : URI,
*** REQUEST ***
GET /home HTTP/1.1
Accept: text/xml
*** RESPONSE ***
200 OK HTTP/1.1
Content-Type: text/xml
Link: <http://alps.io/profiles/webmention-alps.xml>; rel="profile"
.... <payload here> ....
// in the text
"data" : [
{"amount" : "150000", "currency" : "USD", "date" : "20130922"}
]
// valid Cj
"data" : [
{"name" : "amount", "value" : "150000"},
{"name" : "currency", "value" : "USD"},
{"name" : "date", "value" : "20130922"}
@mamund
mamund / cj-items-with-template-links.js
Last active December 26, 2015 15:19
templating w/ homogneous representations in Cj. You can us the `links` collection in a single item to point to templates, too.
@mamund
mamund / workflow-with-cj.js
Created October 26, 2013 22:42
Example of expressing "workflow" (non-CRUD) operations in Cj. Note the first ITEM has one possible "workflow" link (approve") while the second ITEM has three possible "workflow" links (upgrade, downgrade, cancellation).
{"collection" :
{
"version" : "1.0",
"href" : "...",
"links" :
[
{"rel" : "home", "href" : "..."},
{"rel" : "profile", "href" : "..."}
],
@mamund
mamund / gist:7219876
Last active December 26, 2015 21:59
collecting links in Cj templates
{ "collection" :
{
"version" : "1.0",
"href" : "...",
"links" : [
{"rel" : "home", "href" : "..."},
{"rel" : "profile", "href" : "..."}
],
@mamund
mamund / links-v-hypermedia.js
Last active December 27, 2015 12:48
links v hypermedia in JSON
@mamund
mamund / heterogeneous.js
Last active March 20, 2017 17:51
heterogeneous representations w/ Cj
{ "collection" :
{
"version" : "1.0",
"href" : "...",
"items" : [
{ "href" : "http://example.com/users/mike",
"data" : [
{"name" : "type", "value" : "user", "prompt" : "User"},
{"name" : "givenName", "value" : "Mike", "prompt" : "Given Name"},
@mamund
mamund / property-expression.js
Last active December 29, 2015 14:39
difference between expressing properties of a record as structure or data
// structure approach
"item" : {
"id" : "1",
"email" : "mike@example.com",
"familyName" : "amundsen",
"givenName" : "mike"
}
// data approach
"item" : [
@mamund
mamund / task-client-code1.js
Last active January 1, 2016 11:59
sample client code for hypermedia API
var thisPage = function() {
var g = {};
g.msg = {};
g.addUrl = '/tasks/';
g.listUrl = '/tasks/';
g.searchUrl = '/tasks/search?text={@text}';
g.completeUrl = '/tasks/complete/';