REST - basic principles - Where to put the new and edit words

advertisements

I'm wondering where to put the edit, and new keywords by rest application. I'll use express-resource in a project, and the default settings are these:

GET     /forums              ->  index
GET     /forums/new          ->  new
POST    /forums              ->  create
GET     /forums/:forum       ->  show
GET     /forums/:forum/edit  ->  edit
PUT     /forums/:forum       ->  update
DELETE  /forums/:forum       ->  destroy

There is a problem with this solution: there is not a real resource behind the new and edit. I mean the URL-s refer to resources, and after any slash is a sub-resource.

For example:http://my.example.com/users/1 represents:

var firstUser = {
   name: "John Smith",
   birthDate: new Date(1952,10,4),
   hobbies: ["skiing", "football"],
   ...
}

And http://my.example.com/users/1/birthDate represents:

firstUser.birthDate

But by http://my.example.com/users/1/edit there is no such property:

firstUser.edit

So something is wrong with this conception.

Where is the real place of these keywords? In queryString or in headers?


From the perspective of a REST API these do not exist anywhere as they are not related to the representation of resources. They are actions upon resources and therefore expressed by the HTTP methods used. They would not bee needed if you were to create an external client that uses the API.

There is likely a need to provide some support for this type of functionality so that something like a UI could be presented, but that is the concern of the particular application and not the API itself. At that point it becomes discretionary but I would certainly avoid using headers as that would be pretty outside of conventional practice. But by headers it appears that you actually meant URI path. Out of those 2 I would say the path is the better option since it clearly defines any type of UI as a distinct resource and would keep it apart from the clean API, while using a query string on a part of the API would more tightly (mistakenly) associate it with the underlying resource.