<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>

<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-ietf-httpapi-link-template-04" number="9652" obsoletes="" updates="" submissionType="IETF" category="std" consensus="true" tocInclude="true" sortRefs="true" symRefs="true" version="3" xml:lang="en">

  <front>
    <title abbrev="Link-Template">The Link-Template HTTP Header Field</title>
    <seriesInfo name="RFC" value="9652"/>
    <author initials="M." surname="Nottingham" fullname="Mark Nottingham">
      <organization/>
      <address>
        <postal>
          <postalLine>Prahran</postalLine>
          <postalLine>Australia</postalLine>
        </postal>
        <email>mnot@mnot.net</email>
        <uri>https://www.mnot.net/</uri>
      </address>
    </author>
    <date year="2024" month="September"/>

    <area>WIT</area>
    <workgroup>httpapi</workgroup>

    <keyword>link relation</keyword>

    <abstract>
<t>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.</t>
    </abstract>
  </front>
  <middle>

<section anchor="introduction">
      <name>Introduction</name>
      <t><xref target="RFC6570"/> defines a syntax for templates that, when expanded using a set of variables, results in a URI <xref target="RFC3986"/>.</t>
      <t>This specification defines a HTTP header field <xref target="RFC9110"/> for conveying templates for links in the headers of a HTTP message. It is complimentary to the Link header field defined in <xref section="3" sectionFormat="of" target="RFC8288"/>, which carries links directly.</t>
      <section anchor="notational-conventions">
        <name>Notational Conventions</name>
        <t>
    The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>",
    "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL NOT</bcp14>",
    "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>",
    "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
    "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are to be
    interpreted as described in BCP&nbsp;14 <xref target="RFC2119"/> <xref
    target="RFC8174"/> when, and only when, they appear in all capitals, as
    shown here.
        </t>
<t>This specification uses the following terms from <xref target="STRUCTURED-FIELDS"/>: List, String, Display String, and Parameter.</t>
      </section>
    </section>
    <section anchor="the-link-template-header-field">
      <name>The Link-Template Header Field</name>
      <t>The Link-Template header field is a Structured Field <xref target="STRUCTURED-FIELDS"/> that serializes one or more links into HTTP message metadata. It is semantically equivalent to the Link header field defined in <xref section="3" sectionFormat="of" target="RFC8288"/>, except that the link target and link anchor can contain URI Templates <xref target="RFC6570"/>.</t>
      <t>The Link-template header field's value is a List of Strings (see <xref target="STRUCTURED-FIELDS"/>). Each String contains a URI Template and can have Parameters that carry metadata associated with that template.</t>
      <t>For example:</t>
      <sourcecode type="http-message"><![CDATA[
Link-Template: "/{username}"; rel="item"
]]></sourcecode>
      <t>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.</t>
      <t>The link target (see <xref section="2" sectionFormat="of" target="RFC8288"/>) is determined by expanding the template and converting it to an absolute URI (if necessary).</t>
      <t>The link context and link relation type for the link (as defined in <xref section="2" sectionFormat="of" target="RFC8288"/>) are conveyed using the 'anchor' and 'rel' Parameters, as they are for the Link header field in <xref section="3" sectionFormat="of" target="RFC8288"/>. Their values <bcp14>MUST</bcp14> be Strings.</t>
      <t>However, the 'anchor' Parameter <bcp14>MAY</bcp14> contain a URI Template. For example:</t>
      <sourcecode type="http-message"><![CDATA[
Link-Template: "/books/{book_id}/author";
               rel="author"; anchor="#{book_id}"
]]></sourcecode>
      <t>Here, the link to the author for a particular book in a list of books can be found by following the link template.</t>
      <t>This specification defines additional semantics for the 'var-base' Parameter on templated links; see <xref target="the-var-base-parameter" format="default"/>.</t>
      <t>The link's target attributes (as defined in <xref section="2.2" sectionFormat="of" target="RFC8288"/>) are conveyed using other Parameters, in a manner similar to the Link header field. These Parameter values <bcp14>MUST</bcp14> be Strings, unless they contain non-ASCII characters, in which case they <bcp14>MUST</bcp14> be Display Strings. Note that some target attribute names will not serialize as Structured Field Parameter keys (see <xref section="3.1.2" sectionFormat="of" target="STRUCTURED-FIELDS"/>).</t>
      <t>For example:</t>
      <sourcecode type="http-message"><![CDATA[
Link-Template: "/author"; rel="author";
               title=%"Bj%c3%b6rn J%c3%a4rnsida"
]]></sourcecode>
      <t>Implementations <bcp14>MUST</bcp14> support all levels of template defined by <xref target="RFC6570"/> in the link String and the 'anchor' Parameter.</t>
      <section anchor="the-var-base-parameter">
        <name>The 'var-base' Parameter</name>
        <t>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.</t>
        <t>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.</t>
        <t>To determine the URI for a given variable, the value given is used as a base URI in reference resolution (as specified in <xref target="RFC3986"/>). If the resulting URI is still relative, the context of the link is used as the base URI in a further resolution; see <xref target="RFC8288"/>.</t>
        <t>For example:</t>
        <sourcecode type="http-message"><![CDATA[
Link-Template: "/widgets/{widget_id}";
               rel="https://example.org/rel/widget";
               var-base="https://example.org/vars/"
]]></sourcecode>
        <t>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.</t>
        <t>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:</t>
        <sourcecode type="http-message"><![CDATA[
Link-Template: "/widgets/{widget_id}";
               rel="https://example.org/rel/widget";
               var-base="/vars/"
]]></sourcecode>
      </section>
    </section>
    <section anchor="security-considerations">
      <name>Security Considerations</name>
      <t>The security considerations for the Link header field in <xref target="RFC8288"/> and those for URI Templates <xref target="RFC6570"/> apply.</t>
      <t>Target attributes that are conveyed via Display Strings can be vulnerable to a wide variety of attacks. See <xref target="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.</t>
    </section>
    <section anchor="iana-considerations">
      <name>IANA Considerations</name>
      <t>This specification enters the "Link-Template" field name into the "Hypertext Transfer Protocol (HTTP) Field Name Registry".</t>
      <table anchor="http-field-name-registry">
        <name></name>
        <thead>
          <tr>
            <th>Field Name</th>
            <th>Status</th>
            <th>Reference</th>
          </tr>
         </thead>
       <tbody>
         <tr>
           <td>Link-Template</td>
           <td>Permanent</td>
           <td>This document</td>
         </tr>
        </tbody>
      </table>
    </section>
  </middle>
  <back>
    <displayreference target="RFC9110" to="HTTP"/>
    <displayreference target="RFC6570" to="URI-TEMPLATE"/>
    <displayreference target="RFC3986" to="URI"/>
    <displayreference target="RFC8288" to="WEB-LINKING"/>

    <references anchor="sec-normative-references">
      <name>Normative References</name>

      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.9110.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.6570.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.3986.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8288.xml"/>

      <reference anchor="STRUCTURED-FIELDS" target="https://www.rfc-editor.org/info/rfc9651">
        <front>
          <title>Structured Field Values for HTTP</title>
          <author initials="M." surname="Nottingham" fullname="Mark Nottingham">
           <organization>Cloudflare</organization>
          </author>
          <author initials="P-H." surname="Kamp" fullname="Poul-Henning Kamp">
           <organization>The Varnish Cache Project</organization>
          </author>
          <date month="September" year="2024"/>
        </front>
        <seriesInfo name="RFC" value="9651"/>
        <seriesInfo name="DOI" value="10.17487/RFC9651"/>
      </reference>

      <reference anchor="UNICODE-SECURITY" target="https://www.unicode.org/reports/tr36/">
        <front>
          <title>Unicode Security Considerations</title>
          <author initials="M." surname="Davis" fullname="Mark Davis">
            <organization/>
          </author>
          <author initials="M." surname="Suignard" fullname="Michel Suignard">
            <organization/>
          </author>
          <date year="2014" month="September" day="19"/>
        </front>
        <seriesInfo name="Unicode Technical Report" value="#16"/>
        <annotation>Latest version available at <eref target="https://www.unicode.org/reports/tr36/" brackets="angle"/>.</annotation>
      </reference>

      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>

    </references>
  </back>
 </rfc>
