Other people may object to this concept, but it seems reasonable to me:
HEAD /your/api HTTP/1.1 HTTP/1.1 200 OK Date: Fri, 23 Oct 2009 00:58:17 GMT Content-Type: application/xml; charset=UTF-8 Content-Length: 89 X-Result-Count: 100000000
And then:
GET /your/api HTTP/1.1 HTTP/1.1 200 OK Date: Fri, 23 Oct 2009 00:58:17 GMT Content-Type: application/xml; charset=UTF-8 Content-Length: 89 X-Result-Count: 100000000 <?xml version="1.0" encoding="UTF-8"?> <results> 100000000 results go here. </results>
Note: A HEAD request is used here to get a counter without having to pull out a complete set of data. HEAD requests retrieve only HTTP headers, not the response body.
This would be the most RESTful way, I can think about how many results you get before sending it over the wire. The main trick is just right for the best headline for him. X-Result-Count is decent, but if you can find the previous level and reuse your header selection, it will be even better (unless they call it something really stupid). However, I do not expect you to have much luck, so you should stick with the X-Result-Count .
Also, I think you may have misunderstood what “REST” actually means. There is no reason why you cannot provide a range view. For example:
GET /your/api?page=1&perpage=10 HTTP/1.1 HTTP/1.1 200 OK Date: Fri, 23 Oct 2009 00:58:17 GMT Content-Type: application/xml; charset=UTF-8 Content-Length: 101 X-Result-Count: 10 <?xml version="1.0" encoding="UTF-8"?> <results> First 10 results of 100000000 go here. </results>
However, to be RESTful, you must be able to tell the client about the view identified by /your/api?range=0-9 or /your/api?page=1&perpage=10 , without using information out of range. For example, if your page /your/api returns too many results, temporarily redirect to /your/api?page=1&perpage=10 and enable hyperlinks to /your/api?page=2&perpage=10 . Note that a hyperlink in this context may be something simple:
<?xml version="1.0" encoding="UTF-8"?> <results> <result> This is a result. </result> <result> This is also a result. </result> <link rel="next" href="/your/api?page=3&perpage=2" /> <link rel="prev" href="/your/api?page=1&perpage=2" /> </results>
Now the information for navigating the results of your API calls is in-band and virtually RESTful.
In essence, REST is simple HTTP code with caching done correctly and usually sensitive URIs that have been chosen for good measure. It is also “hypertext as an application state mechanism” (that is, resources must refer to other resources). This is not a protocol, this is an architectural style. Anyone who tells you differently is best called Roy Fielding.
Addenda:
If you want to specify a total counter versus the number of pages, you can define the title as follows:
X-Result-Count: 0-9/100000000
Or adjust as needed.