What are the main HTTP methods used in REST APIs and what do they do?

Answer

REST APIs use HTTP methods to indicate the desired action on a resource. GET retrieves a resource or collection — it must be safe (no side effects) and idempotent. POST creates a new resource or triggers an action — it is neither safe nor idempotent. PUT replaces a resource entirely with the provided representation — idempotent but not safe. PATCH applies a partial update to a resource — not required to be idempotent but often is. DELETE removes a resource — idempotent (deleting an already-deleted resource returns 404 or 204). HEAD is identical to GET but returns only headers (no body) — useful for checking resource existence or metadata. OPTIONS returns the HTTP methods supported by the endpoint — used by browsers in CORS preflight requests.