RESTful design question

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

And I can edit it at:

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

On Aug 2, 5:58 pm, emarthinsen [email protected] wrote:

And I can edit it at:

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 # see all events
example.com/events/2 # see event #2
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

Hi Jeff-

That does help. Thanks for your input.

-Eric