# Web API : HTTP VERBS PUT VS POST

We would be aware  that both Put and Post could do both insert and update operation.However we must follow certain standard and choose either of  one verb based on scenario.

Use POST :

1.If  the insert is going to create a new resource/identifier than use POST.

2.Post is not idempotent.

what is Idempotent ?

Idempotent :  Let’s assume we are sending a  request to server with post method  “/create/1” .If we send  multiple request,it would have side effects like creating the resource twice. This might not be the desired output. Other verbs like GET,PUT are Idempotent. If we make a request to server with GET Methods ” /GET/1″ multiple times,it will yield the same result and the same with PUT  “/PUT/1”,it will only update  existing record.

 

POST /resources HTTP/1.1
The post will create new resource
/resources/newresource/

 

Use PUT :

1. If insert or update has to be performed based on existing resource .

2.Put is idempotent.

PUT /resource/<perform operation on existing_resource> 

//Update Resource or create related resource if not existing.

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s