RFC 9264: Linkset: Media Types and a Link Relation Type for Link Sets

  • E. Wilde,  
  • H. Van de Sompel
Proposed Standard

Abstract

This specification defines two formats and associated media types for representing sets of links as standalone documents. One format is based on JSON, and the other is aligned with the format for representing links in the HTTP "Link" header field. This specification also introduces a link relation type to support the discovery of sets of links.

Status of This Memo

This is an Internet Standards Track document.

This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Further information on Internet Standards is available in Section 2 of RFC 7841.

Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at .

1. Introduction

Resources on the Web often use typed Web Links [], either (1) embedded in resource representations -- for example, using the <link> element for HTML documents or (2) conveyed in the HTTP "Link" header field for documents of any media type. In some cases, however, providing links in this manner is impractical or impossible, and delivering a set of links as a standalone document is preferable.

Therefore, this specification defines two formats for representing sets of Web Links and their attributes as standalone documents. One serializes links in the same format as the format used in the HTTP "Link" header field, and the other serializes links in JSON. It also defines associated media types to represent sets of links, and the "linkset" relation type to support the discovery of any resource that conveys a set of links as a standalone document.

2. Terminology

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [] [] when, and only when, they appear in all capitals, as shown here.

This specification uses the terms "link context" and "link target" in the same manner that [] uses them.

In the examples provided in this document, links in the HTTP "Link" header field are shown on separate lines in order to improve readability. Note, however, that as per of "HTTP Semantics" [], line breaks are deprecated in values for HTTP fields; only whitespaces and tabs are supported as separators.

3. Use Cases and Motivation

The following sections describe use cases in which providing links by means of a standalone document instead of in an HTTP "Link" header field or as links embedded in the resource representation is advantageous or necessary.

For all scenarios, links could be provided by means of a standalone document that is formatted according to the JSON-based serialization, the serialization aligned with the HTTP "Link" field format, or both. The former serialization is motivated by the widespread use of JSON and related tools, which suggests that handling sets of links expressed as JSON documents should be attractive to developers. The latter serialization is provided for compatibility with the existing serialization used in the HTTP "Link" field and to allow the reuse of tools created to handle it.

It is important to keep in mind that when providing links by means of a standalone representation, other links can still be provided using other approaches, i.e., it is possible to combine various mechanisms to convey links.

In some cases, it is useful that links pertaining to a resource are provided by a server other than the one that hosts the resource. For example, this allows:

  • Providing links in which the resource is involved not just as a link context but also as a link target, with a different resource being the link context.
  • Providing links pertaining to the resource that the server hosting that resource is not aware of.
  • External management of links pertaining to the resource in a special-purpose link management service.

In such cases, links pertaining to a resource can be provided by another, specific resource. That specific resource may be managed, by the same custodian or by another custodian, as the resource to which the links pertain. For clients intent on consuming links provided in that manner, it would be beneficial if the following conditions were met:

  • Links are provided in a document that uses a well-defined media type.
  • The resource to which the provided links pertain is able to link to the resource that provides these links using a well-known link relation type.

These requirements are addressed in this specification through the definition of two media types and a link relation type, respectively.

3.2. Challenges Writing to the HTTP "Link" Header Field

In some cases, it is not straightforward to write links to the HTTP "Link" header field from an application. This can, for example, be the case because not all required link information is available to the application or because the application does not have the capability to directly write HTTP fields. In such cases, providing links by means of a standalone document can be a solution. Making the resource that provides these links discoverable can be achieved by means of a typed link.

4. Document Formats for Sets of Links

This section specifies two document formats to convey a set of links. Both are based on the abstract model specified in of "Web Linking" [], 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 of []).

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 of []). 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 of [] deprecates the "rev" construct that was provided by [] 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 of [], more specifically by its ABNF [] 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 of [].

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 [] in that the former fully matches the field value of the HTTP "Link" header field as defined in of [], whereas the latter introduces constraints on that definition to meet requirements for Constrained RESTful Environments (CoRE).

4.2. JSON Document Format: application/linkset+json

This document format uses JSON [] as the syntax to represent a set of links. The set of links follows the abstract model defined by of [].

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 of [].

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 Section 6.1 of [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.

A link may be further qualified by target attributes as defined by of []. Three types of attributes exist:

The handling of these different types of attributes is described in the sections below.

4.2.4.1. Target Attributes Defined by Web Linking

of [] 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 [], 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 [].
"media":
The "media" target attribute, defined as optional and not repeatable by [], 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 [].
"title":
The "title" target attribute, defined as optional and not repeatable by [], 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 [], is motivated by character encoding and language issues and follows the model defined in []. 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 [], 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 [].

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" ]
        }
      ]
    }
  ]
}
Figure 4: Linkset with "hreflang" and "type" target attributes
4.2.4.3. Extension Target Attributes

Extension target attributes (e.g., as listed in Section 4.2.4.1) are attributes that are not defined by of [] 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 []), 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 [] 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" } ]
        }
      ]
    }
  ]
}
Figure 6: Linkset with extension target attributes

4.2.5. JSON Extensibility

The Web Linking model [] 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.

5. The "profile" Parameter for Media Types to Represent Sets of Links

As a means to convey specific constraints or conventions (as per []) that apply to a link set document, the "profile" parameter MAY be used in conjunction with the media types "application/linkset" and "application/linkset+json" as detailed in Sections 4.1 and 4.2, respectively. For example, the parameter could be used to indicate that a link set uses a specific, limited set of link relation types.

The value of the "profile" parameter MUST be a non-empty list of space-separated URIs, each of which identifies specific constraints or conventions that apply to the link set document. When providing multiple profile URIs, care should be taken that the corresponding profiles are not conflicting. Profile URIs MAY be registered in the IANA's "Profile URIs" registry in the manner specified by [].

The presence of a "profile" parameter in conjunction with the "application/linkset" and "application/linkset+json" media types does not change the semantics of a link set. As such, clients with and without knowledge of profile URIs can use the same representation.

Section 7.4.2 shows an example of using the "profile" parameter in conjunction with the "application/linkset+json" media type.