2

I read that PUT is used for creating or updating a resource while POST is used for creating a resource.

What would happen if I used POST for updating a resource.

In general why what would happen if i use the wrong verb for wrong request. For example, what would happen if i use GET request to create a new entry in my back end database?

Manas Saxena
  • 2,171
  • 6
  • 39
  • 58
  • 1
    Technically speaking you can code a RESTful api to do whatever it is you want it to, but the reason there are best practices and guidelines is to provide a standardisation. Therefore, those that consume an API understand what is required as it is semantically correct. Also going against the standard REST principals would be a maintenance nightmare. – Corporalis Aug 24 '16 at 14:51

2 Answers2

0

What would happen if I used POST for updating a resource.

If you are the developer then nothing will happen except cofusing the API users and not being in the RESTful best practices.

You can refer to this conversation in order to understand better the difference between the 2 and why it's better to stick with the guidelines.

For example, what would happen if i use GET request to create a new entry in my back end database?

Same answer as above, not in the RESTful spirit neither best practices. But I think that are misunderstanding something in the HTTP protocol though:

GET : is better suited to ask for something.

POST: is better suited to ask for something while providing some information (It goes like this : Hey server! here are some data, and make me some data based on them. This is why it's generally used for updating, because it has a payload, so basically POST = GET + Payload).

Asking if you can use GET to create a new update in a database is kind of non-sense, since GET is generally used just to ask for data. GET does have limited payload information embeded directly in the URL, so you can't separate well the URL from the Payload.

Community
  • 1
  • 1
Ryan B.
  • 1,270
  • 10
  • 24
0

It's all about semantics.

As per REST # 9 Method Definitions,

POST is designed to [..]

So no one can enforce you to apply those rules, even though it was designed to be used in a way (I would say a proper one).

Ioan
  • 5,152
  • 3
  • 31
  • 50
  • 1
    Please, use the newer version specified in RFC 7230-7237 [(in specific 7231)](https://tools.ietf.org/html/rfc7231#section-4.3) rather then the obsolete RFC 2616. – Roman Vottner Aug 24 '16 at 15:32
  • @RomanVottner I was trying to make my point, the version is not really relevant in this context. – Ioan Aug 24 '16 at 16:31