# RESTful design question

**URL:** <https://www.ruby-forum.com/t/restful-design-question/144845>\
**Category:** Rails\
**Created:** [August 3, 2008, 12:59am UTC](https://www.ruby-forum.com/t/restful-design-question/144845 "2008-08-03T00:59:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [August 3, 2008, 12:59am UTC](https://www.ruby-forum.com/t/restful-design-question/144845/1 "2008-08-03T00:59:13Z")

</div>

Hello-

I’m creating an app where someone can register for an event. They can  
only register for one event at a time (the events are all concurrently  
scheduled). I have an event model that has a vanialla model and  
resource. I created a Reservation model and set it up as a singleton  
resource so I can view the current Reservation at something like:

[http://www.example.com/reservation](http://www.example.com/reservation)

And I can edit it at:

[http://www.example.com/reservation/edit](http://www.example.com/reservation/edit)

My question revolves around creating a new reservation. The button to  
create a reservation is on the Event page, so there is no need for a  
“new” action or view for Reservation. I can POST to the Reservation  
path to create a reservation and that works just fine. The thing is, I  
really want to use GET to create a new Reservation so if someone hits  
the back button in their browser, they won’t get that message that the  
browser needs to resend data. Here’s my question. What’s the best way  
to go about this while embracing RESTful design? I’m leaning towards  
creating a new action ( :member =\> { :obtain =\> :get }). I’m also  
pondering bastardizing the existing new method, since I don’t need it  
for anything else. Any recommendations?

Regards-  
Eric

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [August 3, 2008, 6:58am UTC](https://www.ruby-forum.com/t/restful-design-question/144845/2 "2008-08-03T06:58:04Z")

</div>

On Aug 2, 5:58 pm, emarthinsen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> And I can edit it at:
> 
> [http://www.example.com/reservation/edit](http://www.example.com/reservation/edit)

That’s ok, but perhaps as an aside, how do you know what event they’re  
trying to register for?

> My question revolves around creating a new reservation. The button to  
> create a reservation is on the Event page, so there is no need for a  
> “new” action or view for Reservation. I can POST to the Reservation  
> path to create a reservation and that works just fine. The thing is, I  
> really want to use GET to create a new Reservation so if someone hits  
> the back button in their browser, they won’t get that message that the  
> browser needs to resend data. Here’s my question. What’s the best way  
> to go about this while embracing RESTful design?

I wouldn’t recommend this approach, actually. Using GET requests to  
do create or delete data is asking for problems.

The classic (perhaps cliche) example is having a link that would  
delete a reservation. Web crawlers (google, for example) perform GETs  
in order to discover what pages you have on your site. It would be  
unfortunate if following a link meant that reservations could be  
created or deleted.

POST is the recommended action for creating new resources. PUT is for  
updating existing deleting resources. DELETE is for deleting them.

> I’m leaning towards  
> creating a new action ( :member =\> { :obtain =\> :get }).

That’s an indicator that you’re teetering away from a RESTful design.

> I’m also  
> pondering bastardizing the existing new method, since I don’t need it  
> for anything else. Any recommendations?

If you don’t need the new method to show the reservation form, then  
just don’t use it. What were you thinking of doing instead? Perhaps  
there’s a better spot for it.

Based on your original description, I had expected your app to have  
urls like this:

[example.com/events](http://example.com/events) # see all events  
[example.com/events/2](http://example.com/events/2) # see event #2  
[example.com/events/2/reservations/new](http://example.com/events/2/reservations/new) # show new reservation form for  
event #2

Your new reservation form would POST to your create action in your  
Reservations controller.

At least, that’s the typical REST approach. I think trying to make a  
singular Reservation resource is causing more trouble than it’s  
worth…?

Does this help at all?  
Jeff

[http://www.purpleworkshops.com/workshops/rest-and-web-services](http://www.purpleworkshops.com/workshops/rest-and-web-services)

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [August 4, 2008, 10:48pm UTC](https://www.ruby-forum.com/t/restful-design-question/144845/3 "2008-08-04T22:48:17Z")

</div>

Hi Jeff-

That does help. Thanks for your input.

-Eric
