This section specifies two document formats to convey a set of links. Both are based on the abstract model specified in
Section 2 of
RFC 8288, which defines a link as consisting of a "link context", a "link relation type", a "link target", and optional "target attributes":
Links provided in the HTTP "Link" header field are intended to be used in the context of an HTTP interaction, and contextual information that is available during an interaction is used to correctly interpret them. Links provided in link sets, however, can be reused outside of an HTTP interaction, when no such contextual information is available. As a result, implementers of link sets should strive to make them self-contained by adhering to the following recommendations.
For links provided in the HTTP "Link" header field that have no anchor or that use relative references, the URI of the resource that delivers the links provides the contextual information that is needed for their correct interpretation. In order to support use cases where link set documents are reused outside the context of an HTTP interaction, it is
RECOMMENDED to make them self-contained by adhering to the following guidelines:
-
For every link provided in the set of links, explicitly provide the link context using the "anchor" attribute.
-
For the link context ("anchor" attribute) and link target ("href" attribute), use URI references that are not relative references (as defined in Section 4.1 of RFC 3986).
If these recommendations are not followed, the interpretation of links in link set documents will depend on which URI is used as the context.
For a "title" attribute provided on a link in the HTTP "Link" header field, the language in which the title is expressed is provided by the "Content-Language" header field of the HTTP interaction with the resource that delivers the links. This does not apply to "title" attributes provided for links in link set documents because that would constrain all links in a link set to having a single title language and would not support determining title languages when a link set is used outside of an HTTP interaction. In order to support use cases where link set documents are reused outside the context of an HTTP interaction, it is
RECOMMENDED to make them self-contained by using the "title*" attribute instead of the "title" attribute because "title*" allows expressing the title language as part of its value by means of a language tag. Note that, in this regard, language tags are matched case insensitively (see
Section 2.1.1 of
RFC 5646). If this recommendation is not followed, accurately determining the language of titles provided on links in link set documents will not be possible.
Note also that
Section 3.3 of
RFC 8288 deprecates the "rev" construct that was provided by [
RFC 5988] as a means to express links with a directionality that is the inverse of direct links that use the "rel" construct. In both serializations for link sets defined here, inverse links may be represented as direct links using the "rel" construct and by switching the roles of the resources involved in the link.
This document format is nearly identical to the field value of the HTTP "Link" header field as defined in
Section 3 of
RFC 8288, more specifically by its ABNF [
RFC 5234] production rule for "Link" and its subsequent rules. It differs from the format for field values of the HTTP "Link" header field only in that not only spaces and horizontal tabs are allowed as separators but also newline characters as a means to improve readability for humans. The use of non-ASCII characters in the field value of the HTTP "Link" header field is not allowed and as such is also not allowed in "application/linkset" link sets.
The assigned media type for this format is "application/linkset".
When converting an "application/linkset" document to a field value for the HTTP "Link" header field, newline characters
MUST be removed or
MUST be replaced by whitespace (SP) in order to comply with
Section 5.5 of
RFC 9110.
Implementers of "application/linkset" link sets should strive to make them self-contained by following the recommendations provided in
Section 4 regarding their use outside the context of an HTTP interaction.
It should be noted that the "application/linkset" format specified here is different from the "application/link-format" format specified in [
RFC 6690] in that the former fully matches the field value of the HTTP "Link" header field as defined in
Section 3 of
RFC 8288, whereas the latter introduces constraints on that definition to meet requirements for Constrained RESTful Environments (CoRE).
This document format uses JSON [
RFC 8259] as the syntax to represent a set of links. The set of links follows the abstract model defined by
Section 2 of
RFC 8288.
The assigned media type for this format is "application/linkset+json".
In the interests of interoperability, "application/linkset+json" link sets
MUST be encoded using UTF-8 as per
Section 8.1 of
RFC 8259.
Implementers of "application/linkset+json" link sets should strive to make them self-contained by following the recommendations provided in
Section 4 regarding their use outside the context of an HTTP interaction.
The "application/linkset+json" serialization allows for
OPTIONAL support of a JSON-LD serialization. This can be achieved by adding an appropriate context to the "application/linkset+json" serialization using the approach described in [
W3C.REC-json-ld]. Communities of practice can decide which context best meets their application needs.
Appendix A shows an example of a possible context that, when added to a JSON serialization, allows it to be interpreted as Resource Description Framework (RDF) data [
W3C.REC-rdf11-concepts].
In the JSON representation of a set of links:
-
A set of links is represented in JSON as an object that MUST contain "linkset" as its sole member.
-
The value of the "linkset" member is an array in which a distinct JSON object -- the "link context object" (see Section 4.2.2) -- is used to represent links that have the same link context.
-
Even if there is only one link context object, it MUST be wrapped in an array.
In the JSON representation, one or more links that have the same link context are represented by a JSON object -- the link context object. A link context object adheres to the following rules:
-
Each link context object MAY contain an "anchor" member with a value that represents the link context. If present, this value MUST be a URI reference and SHOULD NOT be a relative reference as defined in Section 4.1 of RFC 3986.
-
For each distinct relation type that the link context has with link targets, a link context object MUST contain an additional member. The value of this member is an array in which a distinct JSON object -- the "link target object" (see Section 4.2.3) -- MUST be used for each link target for which the relationship with the link context (value of the encompassing "anchor" member) applies. The name of this member expresses the relation type of the link as follows:
-
For registered relation types (Section 2.1.1 of RFC 8288), the name of this member is the registered name of the relation type.
-
For extension relation types (Section 2.1.2 of RFC 8288), the name of this member is the URI that uniquely represents the relation type.
-
Even if there is only one link target object, it MUST be wrapped in an array.
In the JSON representation, a link target is represented by a JSON object -- the link target object. A link target object adheres to the following rules:
-
Each link target object MUST contain an "href" member with a value that represents the link target. This value MUST be a URI reference and SHOULD NOT be a relative reference as defined in Section 4.1 of RFC 3986. Cases where the "href" member is present but no value is provided for it (i.e., the resource providing the set of links is the target of the link in the link target object) MUST be handled by providing an "href" member with an empty string as its value ("href": "").
-
In many cases, a link target is further qualified by target attributes. Various types of attributes exist, and they are conveyed as additional members of the link target object as detailed in Section 4.2.4.
The following example of a JSON-serialized set of links represents one link with its core components: link context, link relation type, and link target.
{ "linkset":
[
{ "anchor": "https://example.net/bar",
"next": [
{"href": "https://example.com/foo"}
]
}
]
}
The following example of a JSON-serialized set of links represents two links that share a link context and relation type but have different link targets.
{ "linkset":
[
{ "anchor": "https://example.net/bar",
"item": [
{"href": "https://example.com/foo1"},
{"href": "https://example.com/foo2"}
]
}
]
}
The following example shows a set of links that represents two links, each with a different link context, link target, and relation type. One relation type is registered, and the other is an extension relation type.
{ "linkset":
[
{ "anchor": "https://example.net/bar",
"next": [
{"href": "https://example.com/foo1"}
]
},
{ "anchor": "https://example.net/boo",
"https://example.com/relations/baz" : [
{"href": "https://example.com/foo2"}
]
}
]
}
A link may be further qualified by target attributes as defined by
Section 2 of
RFC 8288. Three types of attributes exist:
The handling of these different types of attributes is described in the sections below.
Section 3.4.1 of
RFC 8288 defines the following target attributes that may be used to annotate links: "hreflang", "media", "title", "title*", and "type"; these target attributes follow different occurrence and value patterns. In the JSON representation, these attributes
MUST be conveyed as additional members of the link target object as follows:
-
"hreflang":
-
The "hreflang" target attribute, defined as optional and repeatable by [RFC 8288], MUST be represented by an "hreflang" member, its value MUST be an array (even if there is only one value to be represented), and each value in that array MUST be a string -- representing one value of the "hreflang" target attribute for a link -- that follows the same model as the syntax discussed in [RFC 8288].
-
"media":
-
The "media" target attribute, defined as optional and not repeatable by [RFC 8288], MUST be represented by a "media" member in the link target object, and its value MUST be a string that follows the same model as the syntax discussed in [RFC 8288].
-
"title":
-
The "title" target attribute, defined as optional and not repeatable by [RFC 8288], MUST be represented by a "title" member in the link target object, and its value MUST be a JSON string.
-
"title*":
-
The "title*" target attribute, defined as optional and not repeatable by [RFC 8288], is motivated by character encoding and language issues and follows the model defined in [RFC 8187]. The details of the JSON representation that applies to "title*" are described in Section 4.2.4.2.
-
"type":
-
The "type" target attribute, defined as optional and not repeatable by [RFC 8288], MUST be represented by a "type" member in the link target object, and its value MUST be a string that follows the same model as the syntax discussed in [RFC 8288].
The following example illustrates how the "hreflang" (repeatable) target attribute and the "type" (not repeatable) target attribute are represented in a link target object.
{ "linkset":
[
{ "anchor": "https://example.net/bar",
"next": [
{ "href": "https://example.com/foo",
"type": "text/html",
"hreflang": [ "en" , "de" ]
}
]
}
]
}
In addition to the target attributes described in
Section 4.2.4.1,
Section 3.4 of
RFC 8288 also supports attributes that follow the content model of [
RFC 8187]. In [
RFC 8288], these target attributes are recognizable by the use of a trailing asterisk in the attribute name, such as "title*". The content model of [
RFC 8187] uses a string-based microsyntax that represents the character encoding, an optional language tag, and the escaped attribute value encoded according to the specified character encoding.
The JSON serialization for these target attributes
MUST be as follows:
-
An internationalized target attribute is represented as a member of the link context object with the same name (including the "*") as the attribute.
-
The character encoding information as prescribed by [RFC 8187] is not preserved; instead, the content of the internationalized attribute is represented as a JSON string.
-
The value of the internationalized target attribute is an array that contains one or more JSON objects. The name of one member of such JSON objects is "value", and its value is the actual content (in its unescaped version) of the internationalized target attribute, i.e., the value of the attribute from which the encoding and language information are removed. The name of another, optional member of such JSON objects is "language", and its value is the language tag [RFC 5646] for the language in which the attribute content is conveyed.
The following example illustrates how the "title*" target attribute as defined by
Section 3.4.1 of
RFC 8288 is represented in a link target object.
{ "linkset":
[
{ "anchor": "https://example.net/bar",
"next": [
{ "href": "https://example.com/foo",
"type": "text/html",
"hreflang": [ "en" , "de" ],
"title": "Next chapter",
"title*": [ { "value": "nächstes Kapitel" ,
"language" : "de" } ]
}
]
}
]
}
The above example assumes that the German title contains an umlaut character (in the original syntax, it would be encoded as title*=UTF-8'de'n%c3%a4chstes%20Kapitel), which gets encoded in its unescaped form in the JSON representation. Implementations
MUST properly decode/encode internationalized target attributes that follow the model of [
RFC 8187] when transcoding between the "application/linkset" format and the "application/linkset+json" format.
Extension target attributes (e.g., as listed in
Section 4.2.4.1) are attributes that are not defined by
Section 3.4.1 of
RFC 8288 but are nevertheless used to qualify links. They can be defined by communities in any way deemed necessary, and it is up to them to make sure their usage is understood by target applications. However, lacking standardization, there is no interoperable understanding of these extension attributes. One important consequence is that their cardinality is unknown to generic applications. Therefore, in the JSON serialization, all extension target attributes are treated as repeatable.
The JSON serialization for these target attributes
MUST be as follows:
-
An extension target attribute is represented as a member of the link target object with the same name as the attribute, including the "*" if applicable.
-
The value of an extension attribute MUST be represented by an array, even if there is only one value to be represented.
-
If the extension target attribute does not have a name with a trailing asterisk, then each value in that array MUST be a JSON string that represents one value of the attribute.
-
If the extension attribute has a name with a trailing asterisk (it follows the content model of [RFC 8187]), then each value in that array MUST be a JSON object. The value of each such JSON object MUST be structured as described in Section 4.2.4.2.
The following example shows a link target object with three extension target attributes. The value for each extension target attribute is an array. The first two are regular extension target attributes, with the first one ("foo") having only one value and the second one ("bar") having two. The last extension target attribute ("baz*") follows the naming rule of [
RFC 8187] and therefore is encoded according to the serialization described in
Section 4.2.4.2.
{ "linkset":
[
{ "anchor": "https://example.net/bar",
"next": [
{ "href": "https://example.com/foo",
"type": "text/html",
"foo": [ "foovalue" ],
"bar": [ "barone", "bartwo" ],
"baz*": [ { "value": "bazvalue" ,
"language" : "en" } ]
}
]
}
]
}
The Web Linking model [
RFC 8288] provides for the use of extension target attributes as discussed in
Section 4.2.4.3. The use of other forms of extensions is
NOT RECOMMENDED. Limiting the JSON format in this way allows unambiguous round trips between links provided in the HTTP "Link" header field, sets of links serialized according to the "application/linkset" format, and sets of links serialized according to the "application/linkset+json" format.
Cases may exist in which the use of extensions other than those discussed in
Section 4.2.4.3 may be useful -- for example, when a link set publisher needs to include descriptive or technical metadata for internal consumption. If such extensions are used, they
MUST NOT change the semantics of the JSON members defined in this specification. Agents that consume JSON linkset documents can safely ignore such extensions.