Skip to content

Instantly share code, notes, and snippets.

@semmons99
Last active December 21, 2015 08:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semmons99/6280650 to your computer and use it in GitHub Desktop.
Save semmons99/6280650 to your computer and use it in GitHub Desktop.

Collection+JSON Extensions

1.0 Command Templates

Clients that support the Collection+JSON media type MAY be able to recognize and parse command templates found within responses. Command templates MAY consist of a data array associated with an href property. The commands arrary supports command templates.

For command templates, the name/value pairs of the data array set are sent as JSON in the body ({"id": 1, "members_to_notify": "all"}) or multipart/form-data, both via an HTTP POST.

2.0 commands

The commands array is an OPTIONAL top-level property of the Collection+JSON document.

The commands array SHOULD contain one or more anonymous objects. Each object composed of five possible properties: href (REQUIRED), rel (REQUIRED), name (OPTIONAL), prompt (OPTIONAL), and a data array (OPTIONAL).

If present, the data array represents command parameters for the associated href property of the same object. See Command Templates for details.

// samples commands array

{
  "commands": [
    {
      "href": "/users/disable",
      "rel": "disable",
      "name" "Disable",
      "prompt": "Disable user",
      "data": [
        {"name": "id", "value": "", "prompt": "User id to disable"}
      ]
    },
    ...
    {"href": URI, "rel": STRING, "prompt": STRING, "name": STRING}
  ]
}
@mamund
Copy link

mamund commented Oct 13, 2014

you mention multipart/form-data here. do you mean application/x-www-form-urlencoded or actual multipart (e.g. supporting uploads)? and how (in this extension) does the client determine which to use when sending a POST body?

@semmons99
Copy link
Author

@mamund didn't see this comment until now 😦 We use the prompt to inform the developer if this is an upload endpoint or an action and they use the appropriate content-type though we always accept multipart/form-data.

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