0

What is the actual difference between those two? Both can use request bodies I believe.

I read that PutMapping is used to update data and PostMapping to post new data. Is it more for readable purposes?


flobbe9
  • 3
  • 1
  • Has been discussed already, [see here.](https://stackoverflow.com/questions/630453/put-vs-post-in-rest) – flobbe9 Jun 29 '22 at 09:02

2 Answers2

0

Both of them are shortcuts of:

@RequestMapping(method = RequestMethod.PUT)
@RequestMapping(method = RequestMethod.POST)

POST method call will create a child resource under a collection of resources.

PUT method call will either create a new resource or update an existing one.

NOTE: PUT is an idempotent method while POST is not. For instance, calling the PUT method multiple times will either create or update the same resource. On the contrary, multiple POST requests will lead to the creation of the same resource multiple times.

0

POST:

Used to modify and update a resource

POST /questions/<existing_question> HTTP/1.1 Host: www.example.com/

PUT:

Used to create a resource, or overwrite it. While you specify the resources new URL.

For a new resource:

PUT /questions/<new_question> HTTP/1.1 Host: www.example.com/

flobbe9
  • 26
  • 3