Skip to content

Instantly share code, notes, and snippets.

@hamnis
Last active December 27, 2015 15:59
Show Gist options
  • Save hamnis/7351869 to your computer and use it in GitHub Desktop.
Save hamnis/7351869 to your computer and use it in GitHub Desktop.
{
"collection": {
"href": "http://example.com",
"accept-bulk": "application/vnd.collection-templates+json",
"template": {
"data": [
{"name": "foo"}
]
}
}
}
{
"templates": [
{
"data": [
{"name": "foo", "value": "bar"}
]
},
{
"data": [
{"name": "foo", "value": "baz"}
]
}
]
}
@hamnis
Copy link
Author

hamnis commented Nov 8, 2013

New media type: application/vnd.collection-templates+json or something.

@mamund
Copy link

mamund commented Nov 8, 2013

@hamnis

"templates":[] is an existing extension[1] but not sure it's in use. the array is a safe extension (although i have my reservations about it).

[1] https://github.com/collection-json/extensions/blob/master/templates.md

@mamund
Copy link

mamund commented Nov 8, 2013

seems you could get the same results using this:

{
  "templates": [
      {
        "data": [
          {"name": "foo", "value": "bar"},
          {"name": "foo", "value": "baz"}  
        ]
      }
    ]
}

@hamnis
Copy link
Author

hamnis commented Nov 8, 2013

I knew that the templates extension exists.

I would use a new media type for this, as this is a write-only interaction.

I am also aware that it would be possible to multiple data entries, however this breaks quickly once your template becomes more advanced.

Consider this:

{
  "collection": {
    "href": "http://example.com/events",

    "template": {
      "data": [
        {"name": "timestamp"},
        {"name": "classifier"},
        {"name": "event", "object": {}}
      ]
    }
  }
}

(this is using the "value-types" extension)

If you for instance need to add 100k new events to this, this quickly becomes 100k POSTs.

While I personally don't really have a problem with this, my solution allows multiple POSTs to be merged to one.
Weather this is a good idea or not, remains to be seen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment