<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM 'rfc2629.dtd' []>
<rfc ipr="trust200902" category="info" docName="draft-schuetze-json-hc-01">
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc private=""?>
<?rfc topblock="yes"?>
<?rfc comments="no"?>
<front>
<title abbrev="JSON-HC">JSON-HC</title>

<author initials="J." surname="Schuetze" fullname="J. Schuetze">
<organization></organization>
<address>
<postal>
<street></street>
<city></city>
<code></code>
<country></country>
<region></region>
</postal>
<phone></phone>
<email>jans@dracoblue.de</email>
<uri></uri>
</address>
</author>
<date year="2016" month="August" day="27"/>

<area>Application</area>
<workgroup>Network Working Group</workgroup>
<keyword>JSON</keyword>


<abstract>
<t>This document proposes a media type for representing JSON resources and relations with hypermedia controls.
</t>
</abstract>


</front>

<middle>

<section anchor="jsonhc" title="JSON-HC">
</section>

<section anchor="introduction" title="Introduction">
<t>JSON Hypermedia Controls (JSON-HC) is a standard which
establishes conventions for expressing hypermedia controls in JSON <xref target="RFC4627"/>.
</t>
<t>The Hypermedia Controls of JSON-HC provide a way to figure out which Actions are possible with a Resource Object, what is the self URL of the Object and of which profile is the Resource Object.
</t>
</section>

<section anchor="requirements" title="Requirements">
<t>The key words &quot;MUST&quot; &quot;MUST NOT&quot;, &quot;REQUIRED&quot;, &quot;SHALL&quot;, &quot;SHALL NOT&quot;, &quot;SHOULD&quot;, &quot;SHOULD NOT&quot;, &quot;RECOMMENDED&quot;, &quot;MAY&quot;, and &quot;OPTIONAL&quot; in this document are to be interpreted as described in [RFC2119].
</t>
</section>

<section anchor="jsonhc-documents" title="JSON-HC Documents">
<t>A JSON-HC Document uses the format described in <xref target="RFC4627"/> and has the media type &quot;application/hc+json&quot;.
</t>
<t>Its root object MUST be a Resource Object.
</t>
<t>For example:
</t>

<figure align="center"><artwork align="center">
GET /orders/523 HTTP/1.1
Host: example.org
Accept: application/hc+json

HTTP/1.1 200 OK
Content-Type: application/hc+json

{
  "self": "/orders/523",
  "profile": "https://example.org/rels/order",
  "https://example.org/rels/warehouse": "/warehouse/56",
  "https://example.org/rels/invoice": "/invoices/873",
  "currency": "USD",
  "status": "shipped",
  "total": 10.20
}
</artwork></figure>
<t>Here, we have a JSON-HC document representing an order resource with the URI &quot;/orders/523&quot; and the profile as in <xref target="RFC6906"/> defined as <spanx style="verb">"https://example.org/rels/order"</spanx>. It has &quot;warehouse&quot; and &quot;invoice&quot; links, and its own state in the form of &quot;currency&quot;, &quot;status&quot;, and &quot;total&quot; properties.
</t>
</section>

<section anchor="resource-objects" title="Resource Objects">
<t>A Resource Objects represents a resource.
</t>
<t>It has no reserved properties.
</t>
<t>A Resource Object MAY contain Hypermedia Controls with either a Target URL or an Embedded Resource Object as a value.
</t>
</section>

<section anchor="hypermedia-controls" title="Hypermedia Controls">
<t>Resource Objects MAY contain Hypermedia Controls.
</t>
<t>A Hypermedia Control is a property name, which is either:
</t>
<t>
<list style="symbols">
<t>an IANA link relation name</t>
<t>or a valid URI</t>
</list>
</t>
<t>The value of this Hypermedia Control must be an URL to the linked resource or an Embedded Resource Object.
</t>
<t>If the value is an URL, the Resource Object needs to be fetched ondemand with an additional request.
</t>
</section>

<section anchor="embedded-resource-object" title="Embedded Resource Object">
<t>If the value of an Hypermedia Control is a JSON object, there is no additional request necessary to fetch the Resource Object for this Hypermedia Control.
</t>
</section>

<section anchor="refresh-a-resource-object" title="Refresh a Resource Object">
<t>If the Resource Object has a &quot;self&quot; Hypermedia Control, the value MUST be an URL. A request to the URL will provide the Resource Object.
</t>
</section>

<section anchor="target-url" title="Target URL">
<t>The target URL of an Hypermedia Control is either:
</t>
<t>
<list style="symbols">
<t>the value of an Hypermedia Control, if it is an URL</t>
<t>the &quot;self&quot; Hypermedia Control of the Embedded Resource Object</t>
</list>
</t>
<t>If the Target URL is not an absolute URL, it must start with a &quot;/&quot; and any request to this Target URL will be preceded with the base path of the initially requested Document.
</t>
</section>

<section anchor="performing-actions" title="Performing Actions">
<t>The Target URL of an Hypermedia Control can be used as target for HTTP requests.
</t>
</section>

<section anchor="retrieve-available-http-methods" title="Retrieve available HTTP methods">
<t>JSON-HC does not provide an own way to define, which HTTP methods a JSON-HC Target URL may accept.
</t>
<t>If a server needs to list the possible HTTP methods available for a resource, it SHOULD provide an Allow Header <xref target="RFC7231"/>.
</t>

<figure align="center"><artwork align="center">
OPTIONS /cancelation/123 HTTP/1.1

HTTP/1.1 204 No Content
Allow: POST, OPTIONS
</artwork></figure>
<t>If the resource was requested with an unsupported method, the server should reply with <spanx style="emph">405 Method not Allowed</spanx> HTTP Status Code.
</t>
</section>

<section anchor="profile-of-a-resource-object" title="Profile of a Resource Object">
<t>If the Resource Object has a profile Hypermedia Control, a client can use this to figure out of which kind the Resource Object is.
</t>
</section>

<section anchor="examples" title="Examples">
<t>The following order resource has a self Hypermedia Control as defined by IANA Link Relations and a custom cancel Hypermedia Control.
</t>

<figure align="center"><artwork align="center">
GET /orders/523 HTTP/1.1
Host: example.org
Accept: application/hc+json

HTTP/1.1 200 OK
Content-Type: application/hc+json

{
  "self": "/orders/523",
  "profile": "https://example.org/rels/order",
  "https://example.org/rels/cancel": "/cancelation/873",
  "currency": "USD",
  "status": "created",
  "total": 10.20
}
</artwork></figure>
<t>If the client wants to cancel the order, it does a POST HTTP Request to the cancel Hypermedia Control.
</t>

<figure align="center"><artwork align="center">
POST /cancelation/123 HTTP/1.1

HTTP/1.1 204 No Content
</artwork></figure>
<t>If POST would be not available, the server responds with:
</t>

<figure align="center"><artwork align="center">
HTTP/1.1 405 Method Not Allowed
Allow: DELETE
</artwork></figure>
<t>A client might decide to use DELETE method instead of the hard coded POST method instead.
</t>
</section>

</middle>
<back>
<references title="Informative References">
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4627.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6906.xml"?>
<?rfc include="http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7231.xml"?>
</references>

</back>
</rfc>
