The Link-Template HTTP Header Field
RFC 9652
Mark Nottingham
Prahran
Australia
mnot@mnot.net
https://www.mnot.net/
September 2024
WIT
httpapi
link relation
This specification defines the Link-Template HTTP header field, providing a means for describing the structure of a link between two resources so that new links can be generated.
Introduction
[RFC6570] defines a syntax for templates that, when expanded using a set of variables, results in a URI [RFC3986].
This specification defines a HTTP header field [RFC9110] for conveying templates for links in the headers of a HTTP message. It is complimentary to the Link header field defined in Section 3 of [RFC8288], which carries links directly.
Notational Conventions
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 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
This specification uses the following terms from [STRUCTURED-FIELDS]: List, String, Display String, and Parameter.
The Link-Template Header Field
The Link-Template header field is a Structured Field [STRUCTURED-FIELDS] that serializes one or more links into HTTP message metadata. It is semantically equivalent to the Link header field defined in Section 3 of [RFC8288], except that the link target and link anchor can contain URI Templates [RFC6570].
The Link-template header field's value is a List of Strings (see [STRUCTURED-FIELDS]). Each String contains a URI Template and can have Parameters that carry metadata associated with that template.
For example:

Link-Template: "/{username}"; rel="item"

indicates that a resource with the relation type "item" for a given "username" can be found by expanding the "username" variable into the template given.
The link target (see Section 2 of [RFC8288]) is determined by expanding the template and converting it to an absolute URI (if necessary).
The link context and link relation type for the link (as defined in Section 2 of [RFC8288]) are conveyed using the 'anchor' and 'rel' Parameters, as they are for the Link header field in Section 3 of [RFC8288]. Their values MUST be Strings.
However, the 'anchor' Parameter MAY contain a URI Template. For example:

Link-Template: "/books/{book_id}/author";
               rel="author"; anchor="#{book_id}"

Here, the link to the author for a particular book in a list of books can be found by following the link template.
This specification defines additional semantics for the 'var-base' Parameter on templated links; see Section 2.1.
The link's target attributes (as defined in Section 2.2 of [RFC8288]) are conveyed using other Parameters, in a manner similar to the Link header field. These Parameter values MUST be Strings, unless they contain non-ASCII characters, in which case they MUST be Display Strings. Note that some target attribute names will not serialize as Structured Field Parameter keys (see Section 3.1.2 of [STRUCTURED-FIELDS]).
For example:

Link-Template: "/author"; rel="author";
               title=%"Bj%c3%b6rn J%c3%a4rnsida"

Implementations MUST support all levels of template defined by [RFC6570] in the link String and the 'anchor' Parameter.
The 'var-base' Parameter
When a templated link has a 'var-base' Parameter, its value conveys a URI-reference that is used as a base URI for the variable names in the URI Template. This allows template variables to be globally identified, rather than specific to the context of use.
Dereferencing the URI for a particular variable might lead to more information about the syntax or semantics of that variable; specification of particular formats for this information is out of scope for this document.
To determine the URI for a given variable, the value given is used as a base URI in reference resolution (as specified in [RFC3986]). If the resulting URI is still relative, the context of the link is used as the base URI in a further resolution; see [RFC8288].
For example:

Link-Template: "/widgets/{widget_id}";
               rel="https://example.org/rel/widget";
               var-base="https://example.org/vars/"

indicates that a resource with the relation type "https://example.org/rel/widget" can be found by expanding the "https://example.org/vars/widget_id" variable into the template given.
If the current context of the message that the header appears within is "https://example.org/", the same information could be conveyed by this header field:

Link-Template: "/widgets/{widget_id}";
               rel="https://example.org/rel/widget";
               var-base="/vars/"

Security Considerations
The security considerations for the Link header field in [RFC8288] and those for URI Templates [RFC6570] apply.
Target attributes that are conveyed via Display Strings can be vulnerable to a wide variety of attacks. See [UNICODE-SECURITY] for advice regarding their handling. Specific advice is not given by this specification since there are a variety of potential use cases for such attributes.
IANA Considerations
This specification enters the "Link-Template" field name into the "Hypertext Transfer Protocol (HTTP) Field Name Registry".
Field Name | Status | Reference
Link-Template | Permanent | This document
Normative References
[STRUCTURED-FIELDS]

Structured Field Values for HTTP
Mark Nottingham
Cloudflare
Poul-Henning Kamp
The Varnish Cache Project
September 2024
RFC 9651
DOI 10.17487/RFC9651
[UNICODE-SECURITY]

Unicode Security Considerations
Mark Davis
Michel Suignard
19 September 2014
Unicode Technical Report #16
Latest version available at https://www.unicode.org/reports/tr36/.
[RFC6570]
[RFC3986]
[RFC9110]
[RFC8288]
[RFC2119]
[RFC8174]