Re: API Pagination limit

Philippe Mougin <pmougin@acm.org> Fri, 15 July 2011 05:38 UTC

Return-Path: <ietf-http-wg-request@listhub.w3.org>
X-Original-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Delivered-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 9F75B21F872E for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Thu, 14 Jul 2011 22:38:08 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -10.248
X-Spam-Level:
X-Spam-Status: No, score=-10.248 tagged_above=-999 required=5 tests=[BAYES_00=-2.599, HELO_EQ_FR=0.35, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_HI=-8]
Received: from mail.ietf.org ([64.170.98.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id p3sML-aIeZ3i for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Thu, 14 Jul 2011 22:38:08 -0700 (PDT)
Received: from frink.w3.org (frink.w3.org [128.30.52.56]) by ietfa.amsl.com (Postfix) with ESMTP id DC27A21F8726 for <httpbisa-archive-bis2Juki@lists.ietf.org>; Thu, 14 Jul 2011 22:38:07 -0700 (PDT)
Received: from lists by frink.w3.org with local (Exim 4.69) (envelope-from <ietf-http-wg-request@listhub.w3.org>) id 1Qhb5H-0001TQ-Eu for ietf-http-wg-dist@listhub.w3.org; Fri, 15 Jul 2011 05:37:07 +0000
Received: from lisa.w3.org ([128.30.52.41]) by frink.w3.org with esmtp (Exim 4.69) (envelope-from <pmougin@acm.org>) id 1Qhb5A-0001Re-5y for ietf-http-wg@listhub.w3.org; Fri, 15 Jul 2011 05:37:00 +0000
Received: from smtp12.smtpout.orange.fr ([80.12.242.134] helo=smtp.smtpout.orange.fr) by lisa.w3.org with esmtp (Exim 4.72) (envelope-from <pmougin@acm.org>) id 1Qhb57-0008VB-9O for ietf-http-wg@w3.org; Fri, 15 Jul 2011 05:36:59 +0000
Received: from afontenayssb-151-1-45-102.w83-114.abo.wanadoo.fr ([83.114.219.102]) by mwinf5d23 with ME id 85cV1h0012D99MP035cVF9; Fri, 15 Jul 2011 07:36:31 +0200
X-ME-engine: default
Mime-Version: 1.0 (Apple Message framework v1084)
Content-Type: multipart/alternative; boundary="Apple-Mail-2--458976428"
From: Philippe Mougin <pmougin@acm.org>
In-Reply-To: <43A715E2-14AB-4229-810C-84078E1189C9@opera.com>
Date: Fri, 15 Jul 2011 07:36:28 +0200
Cc: httpbis Group <ietf-http-wg@w3.org>, Jon Masse <jmasse@pheromone.ca>
Message-Id: <07D490DC-0F7F-4C4F-9050-E1E011353328@acm.org>
References: <43A715E2-14AB-4229-810C-84078E1189C9@opera.com>
To: Karl Dubost <karld@opera.com>
X-Mailer: Apple Mail (2.1084)
Received-SPF: pass client-ip=80.12.242.134; envelope-from=pmougin@acm.org; helo=smtp.smtpout.orange.fr
X-W3C-Hub-Spam-Status: No, score=-1.9
X-W3C-Hub-Spam-Report: BAYES_00=-1.9, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001
X-W3C-Scan-Sig: lisa.w3.org 1Qhb57-0008VB-9O bbcde51f6a039ce933179ffd865defb0
X-Original-To: ietf-http-wg@w3.org
Subject: Re: API Pagination limit
Archived-At: <http://www.w3.org/mid/07D490DC-0F7F-4C4F-9050-E1E011353328@acm.org>
Resent-From: ietf-http-wg@w3.org
X-Mailing-List: <ietf-http-wg@w3.org> archive/latest/10943
X-Loop: ietf-http-wg@w3.org
Sender: ietf-http-wg-request@w3.org
Resent-Sender: ietf-http-wg-request@w3.org
Precedence: list
List-Id: <ietf-http-wg.w3.org>
List-Help: <http://www.w3.org/Mail/>
List-Post: <mailto:ietf-http-wg@w3.org>
List-Unsubscribe: <mailto:ietf-http-wg-request@w3.org?subject=unsubscribe>
Resent-Message-Id: <E1Qhb5H-0001TQ-Eu@frink.w3.org>
Resent-Date: Fri, 15 Jul 2011 05:37:07 +0000

Le 14 juil. 2011 à 17:29, Karl Dubost a écrit :

> Hi,
> 
> About API and too large response limit.
> Jon Masse (cced) asked me a question about API and the right HTTP Code to send back to the client. 
> 
> Creating an API returning N posts starting at an index x
> with a limit of N <= 500.
> 
> Someone sends an HTTP GET with n=1000
> http://api.example.org/post?start=1&n=1000
> 
>    GET /post?start=1&n=1000 HTTP/1.1
>    Host: api.example.org
>    User-Agent: FooBar v1
>    Accept: application/json
> 
> What should the API developer send back?
> 
> * 200 OK and a Link for the pagination?
>  Link: </post?start=500&n=500>; rel="Next"
>  (but the client might not know it used an out of range value
> 
> * a 4xx to communicate that there is an out of range value?
>  (but which 4xx? It doesn't seem there is one appropriate.
>  403 doesn't seem right)
> 
> Thanks.

In such situations, I tend to do one of the following:

- Define the resource space in a way that avoid the error condition (e.g., explain that if n is > 500 it will be dealt with as if it was equal to 500). In the description of your resource space, you would specify that the resource at http://api.example.org/post?start={start}&n=500 is also identified by a number of other URLs, of the form http://api.example.org/post?start={start}&n={n}, where n is any integer greater than 500. If your resource space is defined like this, GET http://api.example.org/post?start=1&n=1000 would return a 200 OK and the actual representation of the resource (one with 500 posts).

or

- Define the resource space as exposing resources identified by URLs of the form http://api.example.org/post?start={start}&n={n} where n is an integer between 1 and 500. For the request you describe, answer with a 404 Not Found, because http://api.example.org/post?start=1&n=1000 would not identify an existing resource.

-Philippe