﻿<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM "http://xml.resource.org/authoring/rfc2629.dtd"
[
  <!ENTITY RFC2119 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'>
  <!ENTITY RFC5234 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5234.xml'>
  <!ENTITY RFC5266 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5266.xml'>
  <!ENTITY RFC5988 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5988.xml'>
  <!ENTITY RFC6350 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6350.xml'>
  <!ENTITY RFC6901 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6901.xml'>
  <!ENTITY RFC7159 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.7159.xml'>
  <!ENTITY RFC7230 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.7230.xml'>
  <!ENTITY RFC7480 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.7480.xml'>
  <!ENTITY RFC7481 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.7481.xml'>
  <!ENTITY RFC7482 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.7482.xml'>
  <!ENTITY RFC7483 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.7483.xml'>
  <!ENTITY RFC7942 PUBLIC ''
   'http://xml.resource.org/public/rfc/bibxml/reference.RFC.7942.xml'>
  <!ENTITY W3C.CR-xpath-31-20161213 PUBLIC ''
   'https://xml2rfc.tools.ietf.org/public/rfc/bibxml4/reference.W3C.CR-xpath-31-20161213.xml'>
  <!ENTITY ISO.3166.1988 PUBLIC ''
   'https://xml2rfc.tools.ietf.org/public/rfc/bibxml2/reference.ISO.3166.1988.xml'>
]>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt"?>

<?rfc toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="4"?>
<?rfc compact="yes"?>
<?rfc subcompact="yes"?>
<?rfc sortrefs="yes"?>
<?rfc symrefs="yes"?>
<?rfc iprnotified="no"?>

<rfc category="std" docName="draft-loffredo-regext-rdap-sorting-and-paging-01" ipr="trust200902">
  <front>
    <title abbrev="RDAP Sorting and Paging">Registration Data Access Protocol (RDAP) Query Parameters for Result Sorting and Paging</title>
       
    <author fullname="Mario Loffredo" initials="M." surname="Loffredo">
      <organization>IIT-CNR/Registro.it</organization>
      <address>
        <postal>
          <street>Via Moruzzi,1</street>
          <city>Pisa</city>
          <country>IT</country>
          <code>56124</code>
        </postal>
        <email>mario.loffredo@iit.cnr.it</email>
        <uri>http://www.iit.cnr.it</uri>
      </address>
    </author>

    <author fullname="Maurizio Martinelli" initials="M." surname="Martinelli">
      <organization>IIT-CNR/Registro.it</organization>
      <address>
        <postal>
          <street>Via Moruzzi,1</street>
          <city>Pisa</city>
          <country>IT</country>
          <code>56124</code>
        </postal>
        <email>maurizio.martinelli@iit.cnr.it</email>
        <uri>http://www.iit.cnr.it</uri>
      </address>
    </author>

    <author initials="S." surname="Hollenbeck" fullname="Scott Hollenbeck">
      <organization>Verisign Labs</organization>
      <address>
        <postal>
          <street>12061 Bluemont Way</street>
          <city>Reston</city>
          <region>VA</region>
          <code>20190</code>
          <country>USA</country>
        </postal>
        <email>shollenbeck@verisign.com</email>
        <uri>https://www.verisignlabs.com/</uri>
      </address>
    </author>

    <date/>
    <area>Applications and Real-Time</area>
    <workgroup>Registration Protocols Extensions</workgroup>
    <keyword>RDAP</keyword>
    <keyword>Sorting</keyword>
    <keyword>Paging</keyword>
    
    <abstract>
      <t>The Registration Data Access Protocol (RDAP) does not include core functionality for clients to provide sorting and paging (subsetting) parameters for control of large result sets. This omission can lead to unpredictable server processing of queries and client processing of responses. This unpredictability can be greatly reduced if clients can provide servers with their preferences for managing response values. This document describes RDAP query extensions that allow clients to specify their preferences for sorting and paging result sets.</t>
    </abstract>
  </front>

  <middle>
    <section title="Introduction">
      <t>The availability of functionality for result sorting and paging provides benefits to both clients and servers in the implementation of RESTful services <xref target="REST"/>. These benefits include:</t>
      
        <t><list style="symbols">
	  <t>Reducing the server response bandwidth requirements;</t>
	  <t>Improving server response time;</t>
	  <t>Improvement in query precision and, consequently, obtaining more reliable results;</t>
	  <t>Decreasing server query processing load.</t>
	</list></t>

      <t>Approaches to implementing features for result sorting and paging can be grouped into two main categories:</t>

        <t><list style="numbers">
	  <t>Sorting and paging are implemented through the introduction of additional parameters in the query string (i.e. ODATA protocol <xref target="OData-Part1"/>);<vspace blankLines='1' /></t>
	  <t>Information related to the number of results and the specific portion of the result set to be returned, in addition to a set of ready-made links for the result set scrolling, are inserted in the HTTP header of the request/response.</t>
	</list></t>

      <t>However, there are some drawbacks associated with use of the HTTP header. First, the header properties cannot be set directly from a web browser. Moreover, in an HTTP session, the information on the status (i.e. the session identifier) is usually inserted in the header or in the cookies, while the information on the resource identification or the search type is included in the query string. The second approach is therefore not compliant with the HTTP standard <xref target="RFC7230"/>. As a result, this document describes a specification based on use of query parameters.</t>

      <t>Currently the RDAP protocol <xref target="RFC7482"/> defines two query types:</t>

        <t><list style="symbols">
	  <t>lookup: the server returns only one object;</t>
	  <t>search: the server returns a collection of objects.</t>
	</list></t>

      <t>While the lookup query does not produce issues in the management of large result sets, the search query can potentially generate a large result set that could be truncated according to the limits of the server. In addition, it is not possible to obtain the total number of the objects found that might be returned in a search query response <xref target="RFC7483"/>. Lastly, there is no mechanism to specify sort criteria to return the most relevant objects at the beginning of the result set.</t>

      <t>The protocol described in this specification extends RDAP query capabilities to enable result sorting and paging, by adding four new query parameters that can be applied to RDAP search path segments. The service is implemented using the Hypertext Transfer Protocol (HTTP) <xref target="RFC7230"/> and the conventions described in RFC 7480 <xref target="RFC7480"/>.</t>

      <t>The implementation of these parameters is technically feasible, as operators for counting, sorting and paging rows are currently supported by the major RDBMSs. Impact on the current state of RDAP implementation is estimated to be quite low.</t>
   
      <section title="Conventions Used in This Document">
      	<t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in <xref target="RFC2119"/>.</t>
      </section>
   </section>
      
   <section anchor="rdap-query-parameter-specification" title="RDAP Query Parameter Specification">

      <t>These new query parameters are OPTIONAL extensions of path segments defined in RFC 7482 <xref target="RFC7482"/>. The query parameters are as follows:</t>

        <t><list style="symbols">
	  <t>&quot;count&quot;: a boolean value that allows a client to request the total number of objects found (that due to truncation can be different from the number of returned objects);<vspace blankLines='1' /></t>
	  <t>&quot;sortby&quot;: a string value that allows a client to request a specific sort order for the result set;<vspace blankLines='1' /></t>
	  <t>&quot;limit&quot; and &quot;offset&quot;: numeric values that allow a client to request a specific portion of the entire result set and to use the new &quot;paging_links&quot; property to provide a ready-made reference to the next page of the result set.</t>
	</list></t>

      <t>Augmented Backus-Naur Form (ABNF) <xref target="RFC5234"/> is used in the following sections to describe the formal syntax of these new parameters.</t>
      
      <section anchor="count-parameter" title="&quot;count&quot; Parameter">

      	<t>Currently the RDAP protocol does not allow a client to determine the total number of the results in a query response when the result set is truncated. This is rather inefficient because the user cannot evaluate the query precision and, at the same time, cannot receive information that could be relevant.</t>

      	<t>The new parameter &quot;count&quot; provides additional functionality (<xref target="count-in-query-example"/>) that allows a client to request information from the server that specifies the number of elements found to match a particular search pattern.</t>

      <figure anchor="count-in-query-example" title="Example of RDAP query reporting the count parameter">
        <artwork xml:space="preserve"><![CDATA[
        
https://example.com/rdap/domains?name=*nr.com&count=true
        ]]></artwork>
       </figure>

      	<t>The ABNF syntax is the following:</t>
		<t><list style="empty">
		<t>count = &quot;count&quot; EQ ( trueValue / falseValue )</t>
		<t>trueValue = (&quot;true&quot; / &quot;yes&quot; / &quot;1&quot;)</t>
		<t>falseValue = (&quot;false&quot; / &quot;no&quot; / &quot;0&quot;)</t>
		<t>EQ = &quot;=&quot;</t>
		</list></t>


      	<t>A trueValue means that the server MUST provide the total number of the objects in the paging_count property of the response (<xref target="count-in-response-example"/>). A falseValue means that the server MUST NOT provide this number.</t>

      <figure anchor="count-in-response-example" title="Example of RDAP response with paging_count property">
        <artwork xml:space="preserve">

{
  "rdapConformance": [
	"rdap_level_0",
	"paging_level_0"
  ],
  ...
  "paging_count":"73",
  "domainSearchResults": [
    ...
  ]
}
        </artwork>
       </figure>
      </section>

      <section anchor="sortby-parameter" title="&quot;sortby&quot; Parameter">

	<t>The RDAP protocol does not provide any capability to specify response value sort criteria. A server could implement a default sorting scheme according to the object class, but this feature is not mandatory and might not meet user requirements. Sorting can be addressed by the client, but this solution is rather inefficient. Sorting and paging using features provided by the DBMS used by the RDAP server could help avoid truncation of relevant results and allow for scrolling the result set using subsequent queries.</t>
      
	<t>The &quot;sortby&quot; parameter allows the client to ask the server to sort the results according to the values of one or more properties and according to the sort direction of each property. The ABNF syntax is the following:</t>

	<t><list style="empty">
	<t>sortby = &quot;sortby&quot; EQ sortbyItem *( &quot;,&quot; sortbyItem )</t>
	<t>sortbyItem = property-ref [&quot;:&quot; ( &quot;a&quot; / &quot;d&quot; ) ]</t>
	</list></t>

	<t>&quot;a&quot; means that the ascending sort MUST be applied, &quot;d&quot; means that the descending sort MUST be applied. If the sort direction is absent, an ascending sort MUST be applied (<xref target="sortby-in-query-example"/>).</t>

	<t>In the sortby ABNF syntax, property-ref represents a reference to a property of an RDAP object. Such a reference could be expressed by using a JSON Path. The JSON Path in a JSON document <xref target="RFC7159"/> is equivalent to the XPath <xref target="W3C.CR-xpath-31-20161213"/> in a XML document. For example, the JSON Path to select the value of the ldhName property inside an RDAP domain object is &quot;$.ldhName&quot;, where $ identifies the root of the document (DOM). Another way to select a value inside a JSON document is the JSON Pointer <xref target="RFC6901"/>. While JSON Path or JSON Pointer are both standard ways to select any value inside JSON data, neither is particularly easy to use (e.g. &quot;$.events[?(@.eventAction=&apos;registration&apos;)].eventDate&quot; is the JSON Path expression of the registration date in a RDAP domain object).</t>

	<t>Therefore, this specification provides a definition of property-ref in terms of RDAP properties. However, not all the RDAP properties are suitable to be used in sort criteria, such as:</t>

        <t><list style="symbols">
	  <t>properties providing service information (e.g. links, notices, remarks, etc.);</t>
	  <t>multivalued properties (e.g. status, roles, variants, etc.);</t>
	  <t>properties modeling relationships to other objects (e.g. entities).</t>
	</list></t>

	<t>On the contrary, some properties expressed as values of other properties (e.g. registration date) could be used in such a context.</t>

	<t>In the following, a list of the proposed properties for sort criteria is presented. The properties are divided in two groups, object common properties and object specific properties.</t>

        <t><list style="symbols">
	  <t>Object common properties. Object common properties are derived from the merge of the &quot;eventAction&quot; and the &quot;eventDate&quot; properties. The following values of sortby are defined:
	  <list style="symbols">
	    <t>registrationDate</t>
	    <t>reregistrationDate</t>
	    <t>lastChangedDate</t>
	    <t>expirationDate</t>
	    <t>deletionDate</t>
	    <t>reinstantiationDate</t>
	    <t>transferDate</t>
	    <t>lockedDate</t>
	    <t>unlockedDate</t>
	  </list></t>
	  </list></t>
	  <t><list style="symbols">	  
	  <t>Object specific properties. With regard to the specific properties, some of them are already defined among the query paths. In the following the list of the proposed sorting properties, grouped by objects, is shown:
	  <list style="symbols">
	    <t>Domain: ldhName</t>
	    <t>Nameserver: ldhName, ipV4, ipV6.</t>
	    <t>Entity: fn, handle, org, email, tel, country, countryName, locality.</t>
	  </list></t>
	</list></t>

    <t>In the following, the correspondence between the values of sortby parameter and the RDAP object properties is shown (<xref target="table_sorting_properties_definition"/>):</t>

	<texttable anchor="table_sorting_properties_definition" title="Sorting properties definition">
	<ttcol align="left">Object class</ttcol>
	<ttcol align="left">sortby value</ttcol>
	<ttcol align="left">Object property</ttcol>
	<ttcol align="left">Reference in RFC 7483</ttcol>
	<ttcol align="left">Reference in RFC 6350</ttcol>
	<c>Searchable objects</c><c>Common properties</c><c>eventAction values suffixed by "Date"</c><c>4.5.</c><c></c>
	<c></c><c></c><c></c><c></c><c></c>
	<c>Domain</c><c>ldhName</c><c>ldhName</c><c>5.3.</c><c></c>
	<c></c><c></c><c></c><c></c><c></c>
	<c>Nameserver</c><c>ldhName</c><c>ldhName</c><c>5.2.</c><c></c>
	<c></c><c>ipV4</c><c>v4 ipAddress</c><c>5.2.</c><c></c>
	<c></c><c>ipV6</c><c>v6 ipAddress</c><c>5.2.</c><c></c>
	<c></c><c></c><c></c><c></c><c></c>
	<c>Entity</c><c>handle</c><c>handle</c><c>5.1.</c><c></c>
	<c></c><c>fn</c><c>vcard fn</c><c>5.1.</c><c>6.2.1</c>
	<c></c><c>org</c><c>vcard org</c><c>5.1.</c><c>6.6.4</c>
	<c></c><c>tel</c><c>vcard tel with type="voice"</c><c>5.1.</c><c>6.4.1</c>
	<c></c><c>email</c><c>vcard email</c><c>5.1.</c><c>6.4.2</c>
	<c></c><c>country</c><c>country code (as given in ISO.3166.1988 <xref target="ISO.3166.1988"/>) of the country name in vcard adr</c><c>5.1.</c><c>6.3.1</c>
	<c></c><c>countryName</c><c>country name in vcard adr</c><c>5.1.</c><c>6.3.1</c>
	<c></c><c>locality</c><c>locality in vcard adr</c><c>5.1.</c><c>6.3.1</c>
	</texttable>

	<t>With regard to the definitions in <xref target="table_sorting_properties_definition"/>, some further considerations must be made to disambiguate cases where the RDAP object property is multivalued:</t> 
        <t><list style="symbols">
	  <t>Even if a nameserver can have multiple IPv4 and IPv6 addresses, the most common configuration includes one address for each IP version. Therefore, the assumption of having a single IPv4 and/or IPv6 value for a nameserver cannot be considered too stringent.<vspace blankLines='1' /></t>
          <t>With the exception of handle values, all the sorting properties defined for entity objects can be multivalued according to the definition of vCard as given in RFC6350 <xref target="RFC6350"/>. When more than a value is reported, sorting can be applied to the preferred value identified by the parameter pref="1".</t>  
	</list></t>

	<t>Each RDAP provider MAY define other sorting properties than those shown in this document. (FOR DISCUSSION: how should those properties be defined? Is an IANA registry appropriate?)</t>
	
      <figure anchor="sortby-in-query-example" title ="Examples of RDAP query reporting the sortby parameter">
        <artwork xml:space="preserve"><![CDATA[
        
https://example.com/rdap/domains?name=*nr.com&sortby=ldhName

https://example.com/rdap/domains?name=*nr.com&sortby=registrationDate:d

https://example.com/rdap/domains?name=*nr.com&sortby=lockedDate,ldhName
        ]]></artwork>
       </figure>
      </section>

      <section anchor="limit-and-offset-parameters" title="&quot;limit&quot; and &quot;offset&quot; Parameters">

	<t>An RDAP query could return a response with hundreds of object return values, especially when partial matching is used. For that reason, two parameters addressing result pagination are defined to make responses easier to handle:</t>

        <t><list style="symbols">
	  <t>&quot;limit&quot;: means that the server MUST return the first N objects of the result set in the response;</t>
	  <t>&quot;offset&quot;: means that the server MUST skip the first N objects and MUST return objects starting from position N+1.</t>
	</list></t>

      	<t>The ABNF syntax is the following:</t>

      	<t><list style="empty">
      	<t>EQ = &quot;=&quot;</t>
      	<t>limit = &quot;limit&quot; EQ positive-number</t>
      	<t>offset = &quot;offset&quot; EQ positive-number</t>
      	<t>positive-number = non-zero-digit *digit</t>
      	<t>non-zero-digit = &quot;1&quot; / &quot;2&quot; / &quot;3&quot; / &quot;4&quot; / &quot;5&quot; / &quot;6&quot; / &quot;7&quot; / &quot;8&quot; / &quot;9&quot;</t>
      	<t>digit = &quot;0&quot; / non-zero-digit</t> 
	     </list></t>

	<t>When limit and offset are used together, they allow implementation of result pagination. The following examples illustrate requests to return, respectively, the first 5 objects, the set of objects starting from position 6, and first 5 objects starting from position 11 of the result set (<xref target="limit-and-offset-in-query-example"/>).</t>
	
      <figure anchor="limit-and-offset-in-query-example" title="Examples of RDAP query reporting the limit and offset parameters">
        <artwork xml:space="preserve"><![CDATA[
        
https://example.com/rdap/domains?name=*nr.com&limit=5

https://example.com/rdap/domains?name=*nr.com&offset=5

https://example.com/rdap/domains?name=*nr.com&limit=5&offset=10
        ]]></artwork>
       </figure>

<section anchor="paging_links" title="Use of &quot;paging_links&quot; Property">

      	<t>An RDAP server MAY use the new &quot;paging_links&quot; <xref target="RFC5988"/> property to provide a ready-made reference to the next page of the result set (<xref target="pagination-link-in-response-example"/>).Examples of additional &quot;rel&quot; values are &quot;first&quot;, &quot;last&quot;, &quot;prev&quot;.</t>

      <figure anchor="pagination-link-in-response-example" title="Example of &quot;paging_links&quot; property to implement result pagination">
        <artwork xml:space="preserve"><![CDATA[

{
  "rdapConformance": [
    "rdap_level_0",
    "paging_level_0"
  ],
  ...
  "notices": [
    {
      "title":"Search query limits",
      "type":"result set truncated due to excessive load",
      "description": [
      "search results for domains are limited to 10"
      ]
    }
  ],
  "paging_links": [
    {
      "value":"https://example.com/rdap/domains?name=*nr.com",
      "rel":"next",
      "href":"https://example.com/rdap/domains?name=*nr.com&limit=10
              &offset=10",
      "title": [
        "Result Pagination Link"
      ]
      "type":"application/rdap+json"
    }
  ],
  "paging_count":"73",
  "domainSearchResults": [
    ...
  ]
}
        ]]></artwork>
       </figure>
      </section>
</section>

   </section>


   <section anchor="negative-answers" title="Negative answers">
      <t>The value constraints for the parameters are defined by their ABNF syntax. Therefore, each request providing an invalid value for a parameter SHOULD obtain an HTTP 400 (Bad Request) response code. The same response SHOULD be returned if the client provides an unsupported value for the sortby parameter.</t>

	<t>The server can provide a different response when it supports the limit and/or offset parameters and the client submits values that are out of the valid ranges. The possible cases are:
         <list style="symbols">
	    <t>If the client submits a value for the limit parameter that is greater than the number of objects to be processed, it is RECOMMENDED that server returns a response including only the processed objects.<vspace blankLines='1' /></t>
	    <t>If the client submits a value for the offset parameter that is greater than the number of objects to be processed, it is RECOMMENDED that server returns an HTTP 404 (Not Found) response code.</t>
	  </list></t>
	<t>Optionally, the response MAY include additional information regarding the negative answer in the HTTP entity body.</t>
   </section>

   <section anchor="rdap-conformance" title="RDAP Conformance">
      <t>Servers returning paging_links and paging_count properties MUST include &quot;paging_level_0&quot; in the rdapConformance array of their responses.</t>
   </section>

   <section anchor="implementation-considerations" title="Implementation Considerations">
      <t>The implementation of the new parameters is technically feasible, as operators for counting, sorting and paging are currently supported by the major RDBMSs.</t>

      <t>In the following, the match between the new defined parameters and the SQL operators is shown (<xref target="table_rdap_sql"/>):</t>

	<texttable anchor="table_rdap_sql" title="New query parameters vs. SQL operators">
	<ttcol align="left">New query parameter</ttcol>
	<ttcol align="left">SQL operator</ttcol>
	<c>count</c><c>count(*) query without offset, limit and order by</c>
	<c></c><c><xref target="MYSQL-COUNT"/>,<xref target="POSTGRES-COUNT"/>,<xref target="ORACLE-COUNT"/></c>
	<c></c><c></c>
	<c>sortby</c><c>order by</c>
	<c></c><c><xref target="MYSQL-SORT"/>,<xref target="POSTGRES-SORT"/>,<xref target="ORACLE-SORT"/></c>
	<c></c><c></c>
	<c>limit</c><c>limit n (in MySql <xref target="MYSQL-LIMIT"/> and Postgres <xref target="POSTGRES-LIMIT"/>)</c>
	<c></c><c>FETCH FIRST n ROWS ONLY (in Oracle <xref target="ORACLE-LIMIT"/>)</c>
	<c></c><c></c>
	<c>offset</c><c>offset m (in Postgres)</c>
	<c></c><c>OFFSET m ROWS (in Oracle)</c>
	<c></c><c></c>
	<c>limit + offset</c><c>limit n offset m (in MySql and Postgres)</c>
	<c></c><c>OFFSET m ROWS FETCH NEXT n ROWS ONLY (in Oracle)</c>
	</texttable>

	<t>With regard to Oracle, <xref target="table_rdap_sql"/> reports only one of the three methods that can be used to implement limit and offset parameters. The others are described in <xref target="ORACLE-ROWNUM"/> and <xref target="ORACLE-ROW-NUMBER"/>.</t>
	
	<t>In addition, similar operators are completely or partially supported by the most known NoSQL databases (MongoDB, CouchDB, HBase, Cassandra, Hadoop) so the implementation of the new parameters seems to be practicable by servers working without the use of an RDBMS.</t>
	<t>FOR DISCUSSION: How might this all work without the use of an RDBMS? Would a server need to maintain state information across queries? If so, what are the implications?</t>


   <section anchor="paging-implementation" title="Considerations about Paging Implementation">
    <t>The use of limit and offset operators represents the most common way to implement results pagination. However, when offset has a high value, scrolling the result set could take some time. An alternative approach to offset pagination is the keyset pagination, a.k.a. seek-method (<xref target="SEEK"/>). This method has been taken as the basis for the implementation of a cursor parameter (<xref target="CURSOR"/>) by two REST API providers (<xref target="CURSOR-API1"/>,<xref target="CURSOR-API2"/>). The cursor parameter is an opaque URL-safe string representing a logical pointer to the first result of the next page (<xref target="cursor-based-pagination-link-in-response-example"/>).</t>


      <figure anchor="cursor-based-pagination-link-in-response-example" title="Example of &quot;paging_links&quot; property to implement cursor based pagination">
        <artwork xml:space="preserve"><![CDATA[

{
  "rdapConformance": [
    "rdap_level_0",
    "paging_level_0"
  ],
  ...
  "notices": [
    {
      "title":"Search query limits",
      "type":"result set truncated due to excessive load",
      "description": [
      "search results for domains are limited to 10"
      ]
    }
  ],
  "paging_links": [
    {
      "value":"https://example.com/rdap/domains?name=*nr.com",
      "rel":"next",
      "href":"https://example.com/rdap/domains?name=*nr.com&limit=10
              &cursor=wJlCDLIl6KTWypN7T6vc6nWEmEYe99Hjf1XY1xmqV-M=",
      "title": [
        "Result Pagination Link"
      ]
      "type":"application/rdap+json"
    }
  ],
  "paging_count":"73",
  "domainSearchResults": [
    ...
  ]
}
        ]]></artwork>
       </figure>

   <t>But keyset pagination raises some drawbacks with respect to offset pagination:
         <list style="symbols">
	    <t>it needs at least one key field;</t>
	    <t>it does not allow to sort by any field and paginate the results because sorting has to be made on the key field;</t>
	    <t>it does not allow to skip pages because they have to be scrolled in sequential order starting from the initial page;</t>
	    <t>it makes very hard the navigation of the result set in both directions because all comparison and sort operations have to be reversed.</t>
	  </list></t>

   <t>Furthermore, in the RDAP context, some additional considerations can be made:
         <list style="symbols">
	    <t>an RDAP object is a conceptual aggregation of information collected from more than one data structure (e.g. table) and this makes even harder for the developers the implementation of the seek-method that is already quite difficult. In fact, for example, the entity object can gather information from different data structures (registrars, registrants, contacts, resellers, and so on), each one with its own key field mapping the RDAP entity handle;<vspace blankLines='1' /></t>
	    <t>depending on the number of the page results as well as the number and the complexity of the properties of each RDAP object in the response, the time required by offset to skip the previous pages could be much faster than the processing time needed to build the current page. In fact, RDAP objects can be formed by information belonging to multiple data structures and containing multivalued properties (e.g. arrays) and, therefore, data selection is a time consuming process. This situation occurs even though data selection makes use of indexes;<vspace blankLines='1' /></t>
	    <t>depending on the access levels defined by each RDAP operator, the increase of complexity and the decrease of flexibility of keyset pagination with respect to the offset pagination could be considered impractical.</t>
	  </list></t>

	<t>Finally, the keyset pagination is not fully compliant with the additional RDAP capabilities proposed by this document. In fact, the presence of a possible cursor parameter doesn’t seem to be consistent with both the sorting capability and the possibility to implement additional ready-made links besides the classic &quot;next page&quot; link. But, while the provisioning of more paging links can be superfluous, dropping the sorting capability seems quite unreasonable.</t>
   
	<t>FOR DISCUSSION: Should RDAP specification reports both offset and cursor parameters and let operators to implement pagination according to their needs, the user access levels, the submitted queries?</t>
   </section>

   </section>

    <section anchor="impl-status" title="Implementation Status">
      <t>NOTE: Please remove this section and the reference to RFC 7942 prior to publication as an RFC.</t>
      
      <t>This section records the status of known implementations of the protocol defined by this specification at the time of posting of this Internet-Draft, and is based on a proposal described in RFC 7942 <xref target="RFC7942"/>. The description of implementations in this section is intended to assist the IETF in its decision processes in progressing drafts to RFCs. Please note that the listing of any individual implementation here does not imply endorsement by the IETF. Furthermore, no effort has been spent to verify the information presented here that was supplied by IETF contributors. This is not intended as, and must not be construed to be, a catalog of available implementations or their features. Readers are advised to note that other implementations may exist.</t>
      
      <t>According to RFC 7942, &quot;this will allow reviewers and working groups to assign due consideration to documents that have the benefit of running code, which may serve as evidence of valuable experimentation and feedback that have made the implemented protocols more mature. It is up to the individual working groups to use this information as they see fit&quot;.</t>
      
      <section anchor="iit-cnr-registro-it" title="IIT-CNR/Registro.it">
        <t><list style="none">
	  <t>Responsible Organization: Institute of Informatics and Telematics of National Research Council (IIT-CNR)/Registro.it</t>
	  <t>Location: https://rdap.pubtest.nic.it/</t>
	  <t>Description: This implementation includes support for RDAP queries using data from the public test environment of .it ccTLD. The RDAP server does not implement any security policy because data returned by this server are only for experimental testing purposes. The RDAP server implements both offset and cursor based pagination (the latter only when sortby and offset parameters are not present in the query string).</t>
	  <t>Level of Maturity: This is a "proof of concept" research implementation.</t>
	  <t>Coverage: This implementation includes all of the features described in this specification.</t>
	  <t>Contact Information: Mario Loffredo, mario.loffredo@iit.cnr.it</t>
	</list></t>
      </section>
    </section>

   <section anchor="iana-considerations" title="IANA Considerations">
      <t>FOR DISCUSSION: An IANA-maintained registry could be used to document all of the properties that could be used as sort criteria. Such a registry could also be used to identify the properties for RDAP query filtering capabilities.</t>
   
      <section anchor="rdap-properties-references-registry" title="Registry of References to RDAP Properties">
        <t>Entries in this registry could contain the following:</t>
        
        <t><list style="symbols">
	  	<t>Object class name: the class name of the object the property belongs to (as defined in <xref target="RFC7483"/>);</t>
	  	<t>Property reference: the reference to the property;</t>
	  	<t>JSON Path: the JSON path of the property inside the object (as defined in <xref target="RFC7159"/>);</t>
	  	<t>Published specification: RFC number, bibliographical reference, or URL to a permanent and readily available specification;</t>
	  	<t>Contact: the names and email addresses of individuals to contact regarding this registry entry;</t>
	  	<t>Intended usage: brief reasons for this registry entry (as defined in <xref target="RFC5266"/>).</t>
		</list></t>
		
        <t>In the following, an example of the entry about the reference &quot;ipV4&quot; is reported:</t>
		
		<t><list style="symbols">
	  	<t>Object class name: Nameserver</t>
	  	<t>Property reference: ipV4</t>
	  	<t>JSON Path: $.ipAddresses.v4[0]</t>
	  	<t>Published specification: https://www.ietf.org/id/draft-loffredo-regext-rdap-sorting-and-paging-01.txt</t>
	  	<t>Contact: mario.loffredo@iit.cnr.it</t>
	  	<t>Intended usage: The entry is about the reference to the v4 ip address within a nameserver object.</t>
		</list></t>
      </section>   
   </section>

   <section anchor="security-considerations" title="Security Considerations">
      <t>Security services for the operations specified in this document are described in RFC 7481 <xref target="RFC7481"/>.</t>

      <t>Search query typically requires more server resources (such as memory, CPU cycles, and network bandwidth) when compared to lookup query. This increases the risk of server resource exhaustion and subsequent denial of service due to abuse. This risk can be mitigated by either restricting search functionality and limiting the rate of search requests. Servers can also reduce their load by truncating the results in the response. However, this last security policy can result in a higher inefficiency if the RDAP server does not provide any functionality to return the truncated results.</t>

      <t>The new parameters presented in this document provide the RDAP operators with a way to implement a secure server without penalizing its efficiency. The &quot;count&quot; parameter gives the user a measure to evaluate the query precision and, at the same time, return a significant information. The &quot;sortby&quot; parameter allows the user to obtain the most relevant information at the beginning of the result set. In both cases, the user doesn't need to submit further unnecessary search requests. Finally, the &quot;limit&quot; and &quot;offset&quot; parameters enable the user to scroll the result set by submitting a sequence of sustainable queries according to the server limits.</t>
   </section>

    <section title="Acknowledgements">
      <t>The authors would like to acknowledge Brian Mountford for his contribution to the development of this document.</t>
    </section>

  </middle>
  <back>
    <references title="Normative References">
      &ISO.3166.1988;
      &RFC2119;
      &RFC5234;
      &RFC5266;
      &RFC5988;
      &RFC6350;
      &RFC7159;
      &RFC7230;
      &RFC7480;
      &RFC7481;
      &RFC7482;
      &RFC7483;
    </references>
    
    <references title="Informative References">
    <reference anchor='CURSOR' target='https://www.sitepoint.com/paginating-real-time-data-cursor-based-pagination/'>
		<front>
		<title>Paginating Real-Time Data with Keyset Pagination</title>
		<author initials='R.' surname='Nimesh' fullname='Rakhitha Nimesh'>
		</author>
		<date year='2014' month='July' />		
		</front>
	</reference>
    <reference anchor='CURSOR-API1' target='https://developers.facebook.com/docs/graph-api/using-graph-api'>
		<front>
		<title>facebook for developers - Using the Graph API</title>
		<author>
		<organization>facebook.com</organization>		
		</author>
                <date year='2017' month='July' />	
		</front>
	</reference>
    <reference anchor='CURSOR-API2' target='https://developer.twitter.com/en/docs/tweets/timelines/guides/working-with-timelines'>
		<front>
		<title>Working with timelines</title>
		<author>
		<organization>twitter.com</organization>		
		</author>
                <date year='2017'/>		
		</front>
	</reference>
    <reference anchor='MYSQL-COUNT' target='https://dev.mysql.com/doc/refman/5.7/en/counting-rows.html'>
		<front>
		<title>MySQL 5.7 Reference Manual, Counting Rows</title>
		<author>
		<organization>mysql.com</organization>		
		</author>
		<date year='2015' month='October' />		
		</front>
	</reference>
    <reference anchor='MYSQL-LIMIT' target='https://dev.mysql.com/doc/refman/5.7/en/select.html'>
		<front>
		<title>MySQL 5.7 Reference Manual, SELECT Syntax</title>
		<author>
		<organization>mysql.com</organization>		
		</author>
		<date year='2015' month='October' />		
		</front>
	</reference>
    <reference anchor='MYSQL-SORT' target='https://dev.mysql.com/doc/refman/5.7/en/sorting-rows.html'>
		<front>
		<title>MySQL 5.7 Reference Manual, Sorting Rows</title>
		<author>
		<organization>mysql.com</organization>		
		</author>
		<date year='2015' month='October' />		
		</front>
	</reference>
    <reference anchor='OData-Part1'  target='http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part1-protocol/odata-v4.0-errata03-os-part1-protocol-complete.pdf'>
		<front>
		<title>OData Version 4.0. Part 1: Protocol Plus Errata 03</title>
		<author initials='M.' surname='Pizzo' fullname='Michael Pizzo'>
		</author>
		<author initials='R.' surname='Handl' fullname='Ralf Handl'>
		</author>
		<author initials='M.' surname='Zurmuehl' fullname='Martin Zurmuehl'>
		</author>
		<date year='2016' month='June' />
		</front>
	</reference>
    <reference anchor='ORACLE-COUNT' target='http://docs.oracle.com/database/122/SQLRF/COUNT.htm'>
		<front>
		<title>Database SQL Language Reference, COUNT</title>
		<author>
		<organization>Oracle Corporation</organization>
		</author>
		<date year='2016' month='March' />
		</front>
	</reference>
    <reference anchor='ORACLE-LIMIT' target='http://docs.oracle.com/database/122/SQLRF/SELECT.htm'>
		<front>
		<title>Database SQL Language Reference, SELECT, Row limiting clause</title>
		<author>
		<organization>Oracle Corporation</organization>
		</author>
		<date year='2016' month='March' />
		</front>
	</reference>
    <reference anchor='ORACLE-ROWNUM' target='http://docs.oracle.com/database/122/SQLRF/ROWNUM-Pseudocolumn.htm#SQLRF00255'>
		<front>
		<title>Database SQL Language Reference, SELECT, ROWNUM Pseudocolumn</title>
		<author>
		<organization>Oracle Corporation</organization>
		</author>
		<date year='2016' month='March' />
		</front>
	</reference>
    <reference anchor='ORACLE-ROW-NUMBER' target='http://docs.oracle.com/database/122/SQLRF/ROW_NUMBER.htm#SQLRF06100'>
		<front>
		<title>Database SQL Language Reference, SELECT, ROW_NUMBER</title>
		<author>
		<organization>Oracle Corporation</organization>
		</author>
		<date year='2016' month='March' />
		</front>
	</reference>
    <reference anchor='ORACLE-SORT' target='http://docs.oracle.com/database/122/SQLRF/SELECT.htm'>
		<front>
		<title>Database SQL Language Reference, SELECT, Order by clause</title>
		<author>
		<organization>Oracle Corporation</organization>
		</author>
		<date year='2016' month='March' />
		</front>
	</reference>
    <reference anchor='POSTGRES-COUNT' target='https://www.postgresql.org/docs/9.6/static/functions-aggregate.html'>
		<front>
		<title>PostgresSQL, Aggregate Functions</title>
		<author>
		<organization>postgresql.org</organization>
		</author>
		<date year='2016' month='September' />
		</front>
	</reference>
    <reference anchor='POSTGRES-LIMIT' target='https://www.postgresql.org/docs/9.6/static/queries-limit.html'>
		<front>
		<title>PostgresSQL, LIMIT and OFFSET</title>
		<author>
		<organization>postgresql.org</organization>
		</author>
		<date year='2016' month='September' />
		</front>
	</reference>
    <reference anchor='POSTGRES-SORT' target='https://www.postgresql.org/docs/9.6/static/queries-order.html'>
		<front>
		<title>PostgresSQL, Sorting Rows</title>
		<author>
		<organization>postgresql.org</organization>
		</author>
		<date year='2016' month='September' />
		</front>
	</reference>
    <reference anchor='REST' target='http://www.restapitutorial.com/media/RESTful_Best_Practices-v1_1.pdf'>
		<front>
		<title>RESTful Service Best Practices, Recommendations for Creating Web Services</title>
		<author initials='T.' surname='Fredrich' fullname='Todd Fredrich'>
		</author>
		<date year='2012' month='April' />
		</front>
	</reference>
      &RFC6901;
      &RFC7942;
    <reference anchor='SEEK' target='https://www.eversql.com/faster-pagination-in-mysql-why-order-by-with-limit-and-offset-is-slow/'>
		<front>
		<title>Faster Pagination in Mysql – Why Order By With Limit and Offset is Slow?</title>
		<author>
		<organization>EverSQL.com</organization>
		</author>
		<date year='2017' month='July' />		
		</front>
	</reference>
      &W3C.CR-xpath-31-20161213;
    </references>

    <section title="Change Log">
      <t>
        <list style="hanging">
          <t hangText="00:">Initial version.</t>
          <t hangText="01:">Added the paragraph "Considerations about Paging Implementation" to "Implementation Considerations" section. Added "Implementation Status" section. Added acknowledgements. Renamed the property reporting the paging links</t>
        </list>
      </t>
    </section>
  </back>
</rfc>
