views:

468

answers:

6

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?

+1  A: 

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

It's up to you.

MVC is about the organization/flow of your server-side code and seperating the view from the business layer, not so much about query parameters.

matt b
+17  A: 

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.

Micah
That pretty much covers my opinion as well.
Harper Shelby
+1 Agreed, that is the best option.
Otávio Décio
A: 

It is pretty much up to the dev. I would say put the pageSize in the URL.

Tom Anderson
+5  A: 

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: http://stackoverflow.com/questions?page=2&pagesize=30

JohnRudolfLewis
+3  A: 

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?

JD Conley
A: 

You could also consider the following

Format

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

Example

http://mydomain.com/books/thriller/page/3/results/25
bret
But then, "page" and "results" are basically throwaway route values. I dislike cruft.
Daniel Schaffer
I agree, but I don't see how it's any different than using a query string. It just looks nicer.
bret
It's different because of the semantics. ?page=4 is most certainly defining that the page being requested is 4. /page/4/ doesn't necessarily convey that. This is especially so with multiple values that aren't necessarily hierarchical like "page" and "results". "results" is not a subset or "page", nor vice-versa; IMO, they're on the same "level" of hierarchy, and expressing them in the path, to me, infers some sort of hierarchy that doesn't exist.
Daniel Schaffer