0

Well I know about the idompotence of HTTP methods. I also know about what PUT and POST are specifically used for in REST API. But the question is why use PUT when POST is doing the same.

Take the example of Laravel (PHP Framework), In Laravel we fake POST to be used as PUT method to update the data e.g changing a project name. The question is we can do the same operation i.e updating the project name using POST method without Faking it as PUT then why use PUT?

Majid Alaeinia
  • 962
  • 2
  • 11
  • 27

1 Answers1

0

The http call PUT /products/{id} is idempotent, that is: each subsequent identical call made the same modifications and can be called many times with the same identical result.

The http call POST /products is NOT idempotent, that is, each subsequent identical call should create a new child of the product resource.

PUT is used to UPDATE existing resources, POST is used to CREATE new ones.

Note that, if you want to be REST compliant (as Laravel try to do) you shoud make idempotent GET, PUT, DELETE, HEAD, OPTIONS and TRACE HTTP methods but not the POST method.

Laravel let you faking PUT method calls in a HTML form using a _method parameter because you can't make PUT request with a browser. But, to follow REST principles, Laravel is able to respond to fake PUT call (from the browser) but also to real PUT method coming from others programs with the same route.

dparoli
  • 8,891
  • 1
  • 30
  • 38