0

I was asked below question in the Interview -

If you are hitting the same request with PUT and with POST http method then what will be the difference in payload?

Considering I don't have much experience working in REST, I didn't even know what payload is. I tried googling but didn't find anything conviencing.

Can anyone help?

Jui
  • 55
  • 1
  • 9

2 Answers2

1

according to this page restfulapi.net the PUT request should refer to already existing item (for example in a database connected). In other words, it is meant to update existing item. So the payload don't have to contain all the attributes of the item, just those you want to update.

On the other hand POST is meant to insert new item. This means that the payload should contain (almost) everything.

Thing is, if you send more same PUT requests, the item should remain equivalent to the situation with just one PUT send.

If you send two same POST requests then two new same items (with different ids) will be created. This means that POST requests are not idempotent.

Edit: here might be help too.

1

I didn't even know what payload is.

The interviewer is probably referring to the message-body of the HTTP Request (see RFC 7230).

If you are hitting the same request with PUT and with POST http method then what will be the difference in payload?

This is probably an attempt to explore whether you understand the difference in semantics between the HTTP POST method and the HTTP PUT method.

The PUT method requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload.

Think "save file".

The instructions for POST are a lot less specific

The POST method requests that the target resource process the representation enclosed in the request according to the resource's own specific semantics.

If that seems vague... you're right! The message-body of a POST request can mean almost anything. POST is the "junk drawer" of HTTP methods - anything not worth standardizing goes there.

Community
  • 1
  • 1
VoiceOfUnreason
  • 52,766
  • 5
  • 49
  • 91