This is a specification for hyper+json, which is a json format with hyperlinks.
This example shows almost all the (entirely optional) features at once.
{
"some" : "other property",
"more" : [1,2,3,4],
"_links" : {
"users" : {"href" : "/user"},
"create" : { "href" : "/user",
"method" : "POST",
"schema" : {
"description" : "A user",
"type" : "object",
"properties" : {
"firstname" : {
"type" : "string",
"title" : "First Name"
},
"lastname" : {
"type" : "string",
"title" : "Last Name"
}
}
}
},
"user-search" : {"href" : "/user?name={username}"}
}}
All documents related to the Hyper+JSON mediatype shall use the keywords “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” to describe requirements. These keywords are to be interpreted as described in [RFC2119].
In a hyper+json document, an object or a property of an object with the name _links MUST be considered to be a _links object as defined in this specification.
The _links object MAY be added as a property to any JSON object (a root object, or any number of sub-objects) to represent a list of available “links” as name-value pairs, where the name is the link relation name, and the value is an object describing the available interaction in detail.
The name of a link (in the list of name-value pairs of a _links object) is the relation name that denotes how the given link relates to the current document (as described in detail by http://tools.ietf.org/html/rfc5988). A Hyper+JSON link has a relation name that is similar in nature to the "rel" property of an HTML link but unlike HTML links, its “rel” property is the name for it in the _links object.
eg: Relation in a html link:
<a href="https://github.com/cainus/hyper-json-spec/blob/master/user" rel="users">User</a>
Relation in a hyper+json link:
{"_links" : { "users" : {"href" : "/user"} }}
The actual name used for the relation SHOULD use a standard relation name ( http://www.iana.org/assignments/link-relations/link-relations.xhtml ) where possible.
A link object MUST contain an href
property that denotes the uri for
the given link. The value must either be a uri that conforms to the
uri specification ( https://tools.ietf.org/html/rfc6570 ), or a
uri-template that confirms to the uri-template specification ( https://tools.ietf.org/html/rfc6570 ).
For example:
{
"some" : "other property",
"more" : [1,2,3,4],
"_links" : {
"users" : {"href" : "/user"},
"user-search" : {"href" : "/user?name={username}"}
}}
A link object MAY contain a method
property that denotes the HTTP method ( http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html ) to be used for the given link. If no method
property is provided a client MUST assume that the method is GET. The method
property MUST contain a valid HTTP method. The method MUST be allowed for the resource at the URI specified in the 'href' property.
For example:
{
"some" : "other property",
"more" : [1,2,3,4],
"_links" : {
"remove" : {"href" : "/user/1234", "method" : "DELETE"},
"user-search" : {"href" : "/user?name={username}"}
}}
For links where the HTTP method expects an accompanying HTTP body of type application/json (or a suitable sub-type of application/json), a schema
SHOULD be provided and MUST be a valid JSON Schema document ( See http://json-schema.org/ for details and examples ). The schema MAY be used for validation purposes both on the client and the server, though any given request may be subject to additional validations not described in the schema.
{
"some" : "other property",
"more" : [1,2,3,4],
"_links" : {
"create" : { "href" : "/user",
"method" : "POST",
"schema" : {
"description" : "A user",
"type" : "object",
"properties" : {
"firstname" : {
"type" : "string",
"title" : "First Name"
},
"lastname" : {
"type" : "string",
"title" : "Last Name"
}
}
}
},
"user-search" : {"href" : "/user?name={username}"}
}}