rest put is for create or update

hi,

i was reading below that rest webservices put is for creating
https://www.tutorialspoint.com/restful/restful_introduction.htm

I remember reading some where POST is for create and PUT is to update.

can you please advise which HTTP method for which?

Sr.No.      HTTP Method      URI      Operation      Operation Type
1      GET      /UserService/users      Get list of users      Read Only
2      GET      /UserService/users/1      Get User with Id 1      Read Only
3      PUT      /UserService/users/2      Insert User with Id 2      Idempotent
4      POST      /UserService/users/2      Update User with Id 2      N/A
5      DELETE      /UserService/users/1      Delete User with Id 1      Idempotent
6      OPTIONS      /UserService/users      List the supported operations in web service      Read Only
why it says operation type for POST is N/A where as put is idempotent. what it means?

for working on rest examples why we need both below entries


<dependency>
                  <groupId>javax.ws.rs</groupId>
                  <artifactId>javax.ws.rs-api</artifactId>
                  <version>2.0.1</version>
            </dependency>
            <dependency>
                  <groupId>org.apache.cxf</groupId>
                  <artifactId>cxf-rt-rs-service-description</artifactId>
                  <version>3.0.0-milestone1</version>
            </dependency>


below is fine
<groupId>javax.ws.rs</groupId>
                  <artifactId>javax.ws.rs-api</artifactId>

but why we need cxf as below as well in pom.xml?
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
I remember reading some where POST is for create and PUT is to update.
REST uses HTTP: A POST request identifies the data handler by the URI, not the entitiy. A PUT request identifes the entity changed with the URI.

Richardson Maturity Model and
What is the difference between the HTTP methods POST and PUT?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
girionisCommented:
I remember reading some where POST is for create and PUT is to update.

This is a matter of debate and you will hear different opinions about this. Some people use POST for creation some other use PUT (I personally use PUT). Both are correct.
0
ste5anSenior DeveloperCommented:
Well, gauntlet taken.

POST is to create an entity. Cause the POST URI identifies the data handler, not an entity.
PUT is to update an existing entity, cause the PUT URI identifies the entity.

Thus it's about HTTP semantics and proxy implementation. PUT is defined as idempotent, sending twice the same PUT request has no further effect. POST requests are not idempotent.
Idempotent: the result on the server is the same, independently of how often they are called.
So proxies may filter consecutive PUT requests.

So consider touching an entity three times. When you use a PUT request and your user sits behind a proxy, then this is an action which he can't accomplish.

Thus: POST and PUT are different.

A common pattern found which is ok are lists. It is acceptable to say "POST listUri,  change that object enclosed in the request" in opposite to "PUT objectUri change exactly that object, to the data enclosed in the request". But the difference is, that you don't know which object will be changed, cause this kind of decision is made by the list handler. In opposite to PUT. Here PUT is only allowed the changed the given objectUri. When there is a reason, that this is the wrong URI, PUT must return an error.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

girionisCommented:
I didn't throw any glove so there's nothing to pick up. Please don't start me on idempotency, I know very well what idempotent is and the semantics behind POST and PUT. You said it yourself, PUT is idempotent and this (in my opinion) makes it a perfect candidate for creating a resource, since it also accounts for errors (if you accidentally send the very same request only one entity will be created).

So no argument here, this is a matter that has been debated extensively. You think POST is good for creating I think PUT is, both are correct, it's a matter of preferences.
0
gudii9Author Commented:
Another difference between these two methods is that PUT is supposed to be idempotent, while POST is not. This means that if a PUT request is made N times, the result must be the same for all them. POST method does not have this guarantee.

why put request is made N times result must be same for all of them?

i am not clear on this how result will be same  after PUT operation?
0
gudii9Author Commented:
A common pattern found which is ok are lists. It is acceptable to say "POST listUri,  change that object enclosed in the request" in opposite to "PUT objectUri change exactly that object, to the data enclosed in the request". But the difference is, that you don't know which object will be changed, cause this kind of decision is made by the list handler. In opposite to PUT. Here PUT is only allowed the changed the given objectUri. When there is a reason, that this is the wrong URI, PUT must return an error.

not clear difference between objectUri vs content

can you please elaborate or point to some relevant links, examples, resources?
0
girionisCommented:
why put request is made N times result must be same for all of them?

i am not clear on this how result will be same  after PUT operation?

Imagine that you have a web site that users can open an account with. And now imagine a user that pushes the submit button many times. Would you want this user to be able to open many accounts on your web site or only one?

If you only want the user to open one account and any subsequent requests to be ignored, then your operation should be idempotent.
0
ste5anSenior DeveloperCommented:
why put request is made N times result must be same for all of them?
 i am not clear on this how result will be same  after PUT operation?
This behavior is mandatory per definition for PUT.

PUT is declared to be idempotent. Idempotent means, that the server state after each identical PUT request is the same. As a consequence, the result of each identical PUT request must be the same.
Thus any involved participant in between the client and the destination web server uses this definition. For example web proxies between the client and the web server will now only send the first PUT request of a sequence of identical PUT request to reduce load.

PUT is to update an existing entity, cause the PUT URI identifies the entity.
This is just a general rule.
As an concrete example: The server state (database) don't change, whether is set e.g. Color=Red once or more times. The color is always red afterwards.

Using girionis example: When you call a second "Create Account 123", then the operation must fail, cause you have created it earlier. Here PUT is acceptable for creating the account. Cause you can only create on account 123.

A different example are orders: "Create new Order for Customer 321". This can obviously be called multiple times to create multiple orders. Thus the create call must be POST. Otherwise proxies may no allow it due to the definition of PUT's behavior.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
0
ste5anSenior DeveloperCommented:
not clear difference between objectUri vs content
It's POST listUri vs. PUT objectUri.

The listUri identifies an handler, not an object or entity. The handler can modify any entity (as definied by its requirements or logic). You cannot derive which entity or object is involved from that listUri.

The objectUri identifies an object or entity. The handler called must work on this object to be deterministic.

Content denotes the message body of a HTTP request, which is placed in the body as XML, JSON or even plain text or what ever format your service supports.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
0
girionisCommented:
This is a very delicate subject, since people are "divided" into two camps: those who favour PUT vs those who favour POST, for creating resources. I believe points should be equally divided as well.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.