HTTP methods, also called HTTP verbs, indicate the desired action to be performed on a resource. They are a fundamental part of the HTTP protocol and form the foundation of RESTful API design.
Common HTTP Methods
- GET — Retrieve data. Should not change server state. Cacheable.
- POST — Send data to create a resource or trigger processing.
- PUT — Replace an existing resource entirely with new data.
- PATCH — Partially update an existing resource.
- DELETE — Remove the specified resource.
- HEAD — Like GET but returns only headers, no body. Useful for checking if a resource exists.
- OPTIONS — Returns supported methods for a resource. Used in CORS preflight requests.
Safe vs Idempotent Methods
- Safe methods do not modify the server (GET, HEAD, OPTIONS).
- Idempotent methods produce the same result no matter how many times they are called (GET, PUT, DELETE).
- POST and PATCH are neither safe nor idempotent.