0

I am considering implementing a jump to item's page feature in a REST app, much like StackOverflow's does with questions with multiple answer pages. If you ask for a URL like https://stackoverflow.com/questions/194812/list-of-books/1215215, it will jump to the question's page containing the specific answer (page 4 for this specific case as of this writing). Notice that the client does not request an specific page by number, it requests a page that contains an item of interest and the server needs to resolve the page. In StackOverflow, this is used to get from a user's profile page to the user's answer in context, for example.

I would like to do that within my app, but I can't get to a final (RESTful) design. I've considered the answers to question 776448 and chose to go with the query strings only solution for the base case. But should the app respond a query to an item's page with a 200 response (like StackOverflow does) containing the page with the item, or should it respond with a 302 redirect to the query string version URL? StackOverflow went with the first solution, but which solution do you find more RESTful?

Community
  • 1
  • 1
Thiago Arrais
  • 33,360
  • 7
  • 30
  • 34

2 Answers2

1

I like the idea of a 302 response because it describes exactly the situation: the requested resource resides temporarily at this location (e.g., /.../list-of-books?page=4). This one boils down to personal preference though; there's no restriction on what your URLs look like.

rojoca
  • 11,040
  • 4
  • 45
  • 46
  • The main problem I see with a 302 redirect is that the item may no longer be on that page when the second request hits the server (other items may be added or removed). – Thiago Arrais Nov 01 '10 at 17:22
  • Then you've answered your own question. I like to be pragmatic about decisions like this. If option one will always work as expected and option two won't, ditch the questions around semantics and go with option one. – rojoca Nov 01 '10 at 17:27
0

If I understand what you are asking for, you are looking to implement a fragment identifier.

e.g.

/page/232#Item-2323

The resource you are accessing is /page232 and you want the client to position the UI to be looking at Item-2323. The server ignores everything after the # character.

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
  • I think I missphrased the question. It really wasn't about UI positioning, but how should a REST service respond to a request for a page in a paginated collection resource such that the page includes an specific item. I've changed the question example URL to try to make it more clear. – Thiago Arrais Nov 01 '10 at 15:31