The Link-Template HTTP Header Field
Internet-Draft draft-ietf-httpapi-link-template-00
Mark Nottingham
Prahran
Australia
mnot@mnot.net
https://www.mnot.net/
28 April 2022
Applications and Real-Time
Building Blocks for HTTP APIs
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.
About This Document
The latest revision of this draft can be found at https://ietf-wg-httpapi.github.io/link-template/draft-ietf-httpapi-link-template.html. Status information for this document may be found at https://datatracker.ietf.org/doc/draft-ietf-httpapi-link-template/.
Discussion of this document takes place on the Building Blocks for HTTP APIs Working Group mailing list (mailto:httpapi@ietf.org), which is archived at https://mailarchive.ietf.org/arch/browse/httpapi/.
Source for this draft and an issue tracker can be found at https://github.com/ietf-wg-httpapi/link-template.
Introduction
[URI-TEMPLATE] defines a syntax for templates that, when expanded using a set of variables, results in a URI [URI].
This specification defines a HTTP header field [HTTP] 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 [WEB-LINKING], 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 document uses the Augmented BNF defined in [HTTP] to specify valid protocol elements. Additionally, it uses the modified "parameter" rule from [RFC5987] and the "URI-Template" rule from [URI-TEMPLATE].
The Link-Template Header Field
The Link-Template header field provides a means for serialising one or more links into HTTP message metadata. It is semantically equivalent to the Link header field defined in Section 3 of [WEB-LINKING], except that it uses URI Templates [URI-TEMPLATE] to convey the structure of links.

Link-Template  = "Link-Template" ":" #templated-link
templated-link = "<" URI-Template ">" *( ";" parameter )

For example:

Link-Template: </{username}>; rel="https://example.org/rel/user"

indicates that a resource with the relation type "https://example.org/rel/user" can be found by interpolating the "username" variable into the template given.
The target for the link (as defined in Section 2 of [WEB-LINKING]) is the result of expanding the URI Template [URI-TEMPLATE] (being converted to an absolute URI after expansion, if necessary).
The context, relation type and target attributes for the link are determined as defined for the Link header field in Section 3 of [WEB-LINKING].
Parameters on a templated-link have identical semantics to those of a Link header field. This includes (but is not limited to) the use of the "rel" parameter to convey the relation type, the "anchor" parameter to modify the context IRI, and so on.
Likewise, the requirements for parameters on templated-links are the same as those for a Link header field; in particular, the "rel" parameter MUST NOT appear more than once, and if it does, the templated-link MUST be ignored by parsers.
This specification defines additional semantics for the "var-base" parameter on templated-links; see below.
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 [URI]). If the resulting URI is still relative, the context of the link is used as the base URI in a further resolution; see [WEB-LINKING].
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 interpolating 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 consideration for the Link header field in [WEB-LINKING] and those for URI Templates [URI-TEMPLATE] both apply.
IANA Considerations
This specification enters the "Link-Template" into the Hypertext Transfer Protocol (HTTP) Field Name Registry.

Field Name: Link-Template
Status: permanent
Specification document: [this document]

Normative References
[HTTP]

HTTP Semantics
Roy T. Fielding
Adobe
Mark Nottingham
Fastly
Julian Reschke
greenbytes GmbH
12 September 2021
Internet-Draft draft-ietf-httpbis-semantics-19
[URI-TEMPLATE]

URI Template
J. Gregorio
R. Fielding
M. Hadley
M. Nottingham
D. Orchard
March 2012
RFC 6570
DOI 10.17487/RFC6570
[URI]

Uniform Resource Identifier (URI): Generic Syntax
T. Berners-Lee
R. Fielding
L. Masinter
January 2005
STD 66
RFC 3986
DOI 10.17487/RFC3986
[WEB-LINKING]

Web Linking
M. Nottingham
October 2017
RFC 8288
DOI 10.17487/RFC8288
[RFC2119]

Key words for use in RFCs to Indicate Requirement Levels
S. Bradner
March 1997
BCP 14
RFC 2119
DOI 10.17487/RFC2119
[RFC8174]

Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words
B. Leiba
May 2017
BCP 14
RFC 8174
DOI 10.17487/RFC8174
[RFC5987]

Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters
J. Reschke
August 2010
RFC 5987
DOI 10.17487/RFC5987