Middle
What are the main HTTP methods you know and what are they used for?
sobes.tech AI
Answer from AI
Main HTTP methods and their purpose:
- GET — request a resource. Used to retrieve data from the server. Should not change the state.
- POST — send data to the server, usually for creating new resources or performing actions.
- PUT — replace or create a resource at the specified URI. Idempotent (repeated requests give the same result).
- DELETE — delete a resource.
- HEAD — request headers of a resource without the body. Allows checking existence and metadata.
- OPTIONS — request supported server methods for a resource.
- PATCH — partial update of a resource.
Example:
GET /users/123 HTTP/1.1
Host: example.com
POST /users HTTP/1.1
Host: example.com
Content-Type: application/json
{"name": "Иван"}
Each method has its semantic meaning and should be used according to the specification for proper REST API operation.