Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST status code 204 on paginated result

I am designing a REST like API for paginated data retrieval of a YUI-based client. The REST URL looks like this for a GET request:

/app/catalog/data?startIndex=<int>&results=<int>&sort=<sting>&dir=<string>

All parameters are optional, i.e. if no parameters are given, all data from DB will be dumped. Now say that there are only 1000 records in the database. Following reqeust is made:

/app/catalog/data?startIndex=1100&results=25

What status code should I return if the paginated result from the database remains empty though the request was fine?! I can't decide whether this is 204 or 404.

The produced media types are JSON and CSV.

like image 309
Michael-O Avatar asked Jul 09 '12 19:07

Michael-O


2 Answers

I would say 204 is most appropriate. The request was successful, just with no results.

10.2.5 204 No Content

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation.

Sounds exactly like the case.

like image 177
Michael Boselowitz Avatar answered Nov 15 '22 11:11

Michael Boselowitz


I can't decide whether this is 204 or 404.

Neither. Just return 200 with an empty result (empty XML document or JSON array, whatever you use). Typically I use REST services with paginated views so along with results page I return total number of records. This will help clients to realize the mistake. But technically it is nothing wrong.

Use 204 for DELETE operations (there's really no content to return) and for PUT.

BTW (bold mine):

if no parameters are given, all data from DB will be dumped

Believe, you don't want to do this...

like image 27
Tomasz Nurkiewicz Avatar answered Nov 15 '22 09:11

Tomasz Nurkiewicz