[ 
https://issues.apache.org/jira/browse/QPID-6438?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14355476#comment-14355476
 ] 

Fraser Adams commented on QPID-6438:
------------------------------------

RE: "In many REST best practices it is recommended to use POST requests to 
create REST resources and PUT requests to update/create resources." That seems 
very odd to me!!

As far as I can see PUT should be used to add a resource, DELETE should be used 
to remove a resource and POST should be used to pass information to a resource 
that already exists - the clue is in the name.

My personal preference is for the name to best reflect what you are trying to 
achieve, though it is perfectly possible to use POST to create PUT to update.

I think that the correct answer is actually to choose between PUT and POST 
based on idempotence of the action. There's some good stuff here 
http://stackoverflow.com/questions/630453/put-vs-post-in-rest

PUT implies putting a resource - completely replacing whatever is available at 
the given URL with a different thing. By definition, a PUT is idempotent. Do it 
as many times as you like, and the result is the same. x=5 is idempotent. You 
can PUT a resource whether it previously exists, or not (eg, to Create, or to 
Update)!

POST updates a resource, adds a subsidiary resource, or causes a change. A POST 
is not idempotent, in the way that x++ is not idempotent.

By this argument, PUT is for creating when you know the URL of the thing you 
will create. POST can be used to create when you know the URL of the "factory" 
or manager for the category of things you want to create.

so:

POST /expense-report

or:

PUT  /expense-report/10929



> [Java Broker] Add support for POST method into REST interfaces in order to 
> create configured objects via POST
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: QPID-6438
>                 URL: https://issues.apache.org/jira/browse/QPID-6438
>             Project: Qpid
>          Issue Type: Improvement
>          Components: Java Broker
>    Affects Versions: 0.18, 0.20, 0.22, 0.24, 0.26, 0.28, 0.30, 0.32
>            Reporter: Alex Rudyy
>            Assignee: Alex Rudyy
>             Fix For: 6.0 [Java]
>
>
> PUT method requests are used for both configured object creation and their 
> updates. Our REST layer looks for ID or name( coupled with object parent) in 
> order to decide whether it is an update request or not.
> Update is made when object with the same id or the same name and parent is 
> found. Otherwise a new object is created.
> On creation of new configured objects(for example, virtual host nodes) the 
> same name as existing object can be specified by mistake. As result, an 
> update request is performed causing updating attributes in existing object 
> and saving those attributes in the database. In practice, it might cause 
> configuration issues, for instance,
> if user tries to create a new BDB HA VHN and specifies an existing VHN name, 
> the existing VHN attributes are updated and on next broker restart a new VHN 
> with a new store can be created.
> In many REST best practices it is recommended to use POST requests to create 
> REST resources and PUT requests to update/create resources.
> We can use the same approach in the Qpid REST layer, i.e. send POST requests 
> if we definitely want to create new objects via web management console or REST



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to