Sobes.tech
Middle

What is the difference between GET and POST?

sobes.tech AI

Answer from AI

GET and POST are two main HTTP methods with different purposes:

  • GET is used to request data from the server. It is safe and idempotent, with parameters passed in the URL (query string). It usually does not change the server state.

  • POST is used to send data to the server, for example, when creating or updating resources. Data is sent in the request body. POST can change the server state and is not idempotent.

Example:

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

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

{"title": "Buy milk", "done": false}

GET requests the todo with id=123, POST creates a new todo.