Sobes.tech
Middle

What are the main HTTP request methods? What is the difference between GET and POST?

sobes.tech AI

Answer from AI

Main methods of HTTP requests:

  • GET — retrieving data from the server.
  • POST — sending data to the server to create a resource.
  • PUT — updating an existing resource.
  • DELETE — deleting a resource.
  • PATCH — partially updating a resource.
  • HEAD — obtaining only the response headers.

Differences between GET and POST:

  • GET is used for requesting data, parameters are passed in the URL, requests are cached and can be cached by the browser.
  • POST is used for sending data to the server, parameters are passed in the request body, it is not cached and suitable for operations that change the server state.

Example of a GET request:

GET /api/users?id=123 HTTP/1.1
Host: example.com

Example of a POST request:

POST /api/users HTTP/1.1
Host: example.com
Content-Type: application/json

{"name": "Ivan", "age": 30}