Search code examples
restspring-mvcput

Hidden html inputs versus using a pathVariable in the URL of a PUT HTTP request


My application currently makes massive use of hidden inputs such as:

<input type="hidden" name="id" value="123456"/>

For instance, using the above hidden input I can keep the id/pk of my object without displaying it to the end user.

I feel this goes against the principles of REST and I would like to know whether using a PUT url such as:

/advertisement/childminder/123456/edit

and doing away with the hidden input altogether might not be a better idea...

Can anyone please advise?

edit: I have edited my question and changed from POST to PUT because I am dealing with modification and not creation.


Solution

  • Having an "edit" as part of the URL smells of RPC-over-HTTP style programming. And tunneling edits through POST is also considered an REST anti-pattern.

    REST is about putting the verbs in the HTTP method and using hypertext. Stefan Tilkov had an old but helpful introduction to REST that addresses your question.

    Short: Wikipedia: REST - RESTful web APIs (especially the usage of POST: Don't use it for edits on none-collections - use it for creation)!