# Action names in RESTful URLs

**URL:** <https://www.ruby-forum.com/t/action-names-in-restful-urls/192067>\
**Category:** Rails\
**Created:** [July 23, 2010, 9:19am UTC](https://www.ruby-forum.com/t/action-names-in-restful-urls/192067 "2010-07-23T09:19:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSSSSSric\_Malenfant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@SSSSSSric\_Malenfant](https://www.ruby-forum.com/u/SSSSSSric_Malenfant)\
**Post date:** [July 23, 2010, 9:19am UTC](https://www.ruby-forum.com/t/action-names-in-restful-urls/192067/1 "2010-07-23T09:19:49Z")

</div>

A probably noob-ish question about the restful urls, but I searched  
the groups archives and could not find it.

IIUC, “GET /users/bob” should return a page showing information about  
the user identified with “bob”, while “GET /users/new” returns a page  
with a form for creating a new user.

Ain’t there an ambiguity there? Does that mean that I have to make  
sure that no user chooses “new” as his id?

---

<div class="post-metadata">

**Author:** ![SSSSSSric\_Malenfant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@SSSSSSric\_Malenfant](https://www.ruby-forum.com/u/SSSSSSric_Malenfant)\
**Post date:** [July 23, 2010, 2:21pm UTC](https://www.ruby-forum.com/t/action-names-in-restful-urls/192067/2 "2010-07-23T14:21:54Z")

</div>

On Thu, Jul 22, 2010 at 19:04, Éric Malenfant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> A probably noob-ish question about the restful urls, but I searched  
> the groups archives and could not find it.
> 
> IIUC, “GET /users/bob” should return a page showing information about  
> the user identified with “bob”, while “GET /users/new” returns a page  
> with a form for creating a new user.
> 
> Ain’t there an ambiguity there? Does that mean that I have to make  
> sure that no user chooses “new” as his id?

If you retrieve them by name, yes, but usually what I’ve seen,  
especially with Rails, is retrieval by ID number. So, you’d have GET  
/users/23 or whatever, who may happen to be named Bob. Or if you want  
to get them by name, GET /users/search?name=bob, or maybe even  
/users/show?name=bob, or if the name isn’t unique, possibly  
/users/index?name=bob.

-Dave

–  
Specialization is for insects. | Professional: [http://davearonson.com](http://davearonson.com)  
-Robert Anson Heinlein | Programming: [http://codosaur.us](http://codosaur.us)  
-------------------------------+ Leadership: [http://dare2xl.com](http://dare2xl.com)  
Have Pun, Will Babble! -me | Et Cetera: [http://davearonson.net](http://davearonson.net)

---

<div class="post-metadata">

**Author:** ![SSSSSSric\_Malenfant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@SSSSSSric\_Malenfant](https://www.ruby-forum.com/u/SSSSSSric_Malenfant)\
**Post date:** [July 23, 2010, 6:56pm UTC](https://www.ruby-forum.com/t/action-names-in-restful-urls/192067/3 "2010-07-23T18:56:47Z")

</div>

Ã‰ric Malenfant wrote:

> A probably noob-ish question about the restful urls, but I searched  
> the groups archives and could not find it.
> 
> IIUC, “GET /users/bob” should return a page showing information about  
> the user identified with “bob”, while “GET /users/new” returns a page  
> with a form for creating a new user.
> 
> Ain’t there an ambiguity there? Does that mean that I have to make  
> sure that no user chooses “new” as his id?

If you use such “permalinks” to identify the individual resources  
instead of their primary key id, then you’ll need to make sure you add  
validation to make sure the resource URI is unique. “GET /users/new” is  
itself a resource identifier URI. It refers to the “New Form” resource.  
Similarly the “Edit Form” resource has the “GET /users/edit” identifier  
URI.

Using the model’s simple integer primary key in the resource URI  
eliminates this issue. I’ve seen some people combine the id with a  
textual identifier to produce URI’s like “GET /users/1-bob” which would  
also solve this issue. “GET /users/2-new” would be distinct from “GET  
/users/new” so there would be no conflict. As a bonus the resource can  
still be easily queried by primary key by parsing “1-bob” into the  
integer 1, which matches the id for Bob’s record.

@user = User.find(“1-bob”.to\_i) # User.find(1)
