Middle
What HTTP methods are there and what are they used for?
sobes.tech AI
Answer from AI
Main HTTP methods and their purpose:
- GET — retrieve a resource. Safe and idempotent method, does not change server state.
- POST — create a new resource or perform an action. Can change state, not idempotent.
- PUT — replace the entire resource. Idempotent.
- PATCH — partially update a resource. Not always idempotent.
- DELETE — delete a resource. Idempotent.
- HEAD — get only the headers of a resource, without the body.
- OPTIONS — find out supported methods and server capabilities for a resource.
Example: for REST API
- GET /users/123 — get user with id 123
- POST /users — create a new user
- PUT /users/123 — replace data of user 123
- PATCH /users/123 — update part of user 123's data
- DELETE /users/123 — delete user 123
Understanding these methods is important for proper design and use of web services.