cdeszaq
cdeszaq

Reputation: 31280

Which simple REST URL pattern is more common / better?

/controller/action/id

or

/controller/id/action

Which is more common? Which is preferable and why?

Are there any pro's / con's of using one or the other?


Edit:

Or, perhaps to think of this question in a different way, why do most MVC frameworks (ASP.Net MVC, Grails, Spring MVC) default to the /controller/action/id URL pattern? Is there some advantage to this?

Upvotes: 0

Views: 996

Answers (3)

Nicholas Shanks
Nicholas Shanks

Reputation: 10971

Neither of these are RESTful. There should not be verbs/actions in a URL. Those are confined to the HTTP method for good reason (so that clients can interact with your service without knowing anything specific about it).

If you can not do anything except GET and POST, use POST to send an action parameter to /controller/id

Upvotes: 2

CPhelps
CPhelps

Reputation: 279

I definitely prefer /controller/action/id. This feels to me more like it is identifying a resource (a noun) rather than identifying an action on that noun (a verb).

In addition to the exact URL to the resource, you need to consider how you are mapping the HTTP verbs. In my experience, we have shuffled the URL around based on what made most sense when combined with the verbs. That said, we also have a couple places we broke the canonical approach for convenience sake (for example, exposing a certain delete action with a GET so that users could perform the action via a browser).

Also take a look at this discussion for more. REST URL structure advice

Upvotes: 0

Craig
Craig

Reputation: 7076

Asp.Net MVC uses /controller/action/id. So that is what you'll most often see in that environment. I do not see any technical benefits but simply going with a common pattern can make things easier to understand.

Upvotes: 0

Related Questions