Friday, 31 December 2021

GET, PUT, POST, DELETE best practice. Query data vs POST/PUT Data

 https://stackoverflow.com/questions/630453/what-is-the-difference-between-post-and-put-in-http


POST:

Used to modify and update a resource


PUT:

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



GET:

Used to fetch a resource



DELETE:

Used to delete a resource




Difference between sending data via URL(GET, DELETE, a part of PUT(PUT server/overwriteUser?id=1...with POST DATA), VS sending data in the request it self in form of content-type: application/json or application/x-www-form-urlencoded



GET with sending data via url :


<form action="http://www.foo.com" method="GET">

  <div>

    <label for="say">What greeting do you want to say?</label>

    <input name="say" id="say" value="Hi">

  </div>

  <div>

    <label for="to">Who do you want to say it to?</label>

    <input name="to" id="to" value="Mom">

  </div>

  <div>

    <button>Send my greetings</button>

  </div>

</form>


GET /?say=Hi&to=Mom HTTP/2.0
Host: foo.com






POST with sending data in request(x-wwww-form-urlencoded):


<form action="http://www.foo.com" method="POST">

  <div>

    <label for="say">What greeting do you want to say?</label>

    <input name="say" id="say" value="Hi">

  </div>

  <div>

    <label for="to">Who do you want to say it to?</label>

    <input name="to" id="to" value="Mom">

  </div>

  <div>

    <button>Send my greetings</button>

  </div>

</form>


POST / HTTP/2.0
Host: foo.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 13

say=Hi&to=Mom







No comments:

Post a Comment