views:

15

answers:

1

Background - I have a model, say Door, that has a state of open or closed. I encapsulate the behaviour of opening the door in a method #open on each instance (And I also have a #close equivalent).

But what's the best way to expose this in a RESTful way? What should my route be?

It is an UPDATE to Door instance, but what should I UPDATE with?

Cheers, Gordon

+1  A: 

There is no one best way that everybody would agree on.

Some people would add two custom actions open and close to their controllers, which would then call the respective methods on the Door model.

Other people would use the update controller method to change whatever attribute the door uses to store its open/closed state. e.g. a boolean field closed. They might also argue that you should not have dedicated open and close methods besides the closed attribute, and that you implement with validations and callbacks whatever open/close used to encapsulate.

My recommendation is not to worry too much about RESTfulness and always choose the most practical way.

henning-koch
Thanks henning-koch, there is a strange comfort in knowing there is no best way! Probably because I expected it!
Gordon McAllister