Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MVC, should pagination info go in the path or querystring?

In the path:

Format: http://mydomain.com/{category}/{subcategory}/{pageNumber}/{pageSize}

Example: http://mydomain.com/books/thriller/3/25

In the querystring:

Format: http://mydomain.com/{category}/{subcategory}? pageNumber={pageNumber}&pageSize={pageSize}

Example: http://mydomain.com/books/thriller?pageNumber=3&pageSize=25

I like having everything on the path, but my problem with that is that while it is obvious (or at least somewhat obvious) what "books" and "thriller" are in first example, the "3" and "25" seem pretty arbitrary by contrast.

Is there a canonical method for determining what goes where in MVC, or is it really just up to the dev?

like image 641
Daniel Schaffer Avatar asked Jan 12 '09 20:01

Daniel Schaffer


3 Answers

I prefer things like pagenumbers to be in the querystring variables. I think there's a difference in descriptiveness between

http://mydomain.com/books/thriller?pagesize=50&page=4

and

http://mydomain.com/books/thriller/50/4

The point (to me) of having clean url's is for them to be more descriptive and readable, and I find the first example to be just that.

One interesting point made byJohnRudolfLewis is:

One rule of thumb that I follow is that if the argument is required, consider using the path, if the argument is optional, always use querystring arguments.

like image 104
Micah Avatar answered Oct 21 '22 05:10

Micah


One rule of thumb that I follow is that if the argument is required, consider using the path, if the argument is optional, always use querystring arguments.

Overall, I'd stick to whatever makes the url look more readable.

This site puts it in the querystring: https://stackoverflow.com/questions?page=2&pagesize=30

like image 32
JohnRudolfLewis Avatar answered Oct 21 '22 04:10

JohnRudolfLewis


Well, it's obviously up to you. But, you're designing a RESTful interface that's supposed to be human readable. The querystring is much better in that regard. Otherwise you're looking at two numbers that could really be anything. And who's going to remember the order?

like image 30
JD Conley Avatar answered Oct 21 '22 04:10

JD Conley