Skip to content
Last updated

HTTP methods, also known as verbs, define the type of action to be performed on a given resource. Each method provides a different type of functionality. Here are the commonly used HTTP methods in an API:

GET

Description: The GET method is used to retrieve data from a server.

PropertyValue
Use CaseFetching data, such as a list of users or a specific user profile.
IdempotentYes
SafeYes

POST

Description: The POST method is used to send data to a server to create a new resource.

PropertyValue
Use CaseCreating a new user or submitting a form.
IdempotentNo
SafeNo

PUT

Description: The PUT method is used to update an existing resource or create a new resource if it doesn't exist.

PropertyValue
Use CaseUpdating user details or replacing a specific resource.
IdempotentYes
SafeNo

PATCH

Description: The PATCH method is used to apply partial modifications to a resource.

PropertyValue
Use CaseUpdating specific fields of a user profile.
IdempotentYes
SafeNo

DELETE

Description: The DELETE method is used to remove a specified resource from a server.

PropertyValue
Use CaseDeleting a user or removing a specific item.
IdempotentYes
SafeNo

What is Idempotent?

An HTTP method is idempotent if making multiple identical requests produces the same result as making a single request. In other words, calling an idempotent method multiple times will leave the server in the same state as calling it once.

Examples:

  • PUT - Updating a user's name to "John" once or five times results in the same state: the name is "John"
  • DELETE - Deleting a resource once or five times results in the same state: the resource is deleted
  • GET - Retrieving data multiple times doesn't change the server state

Idempotent Methods: GET, PUT, PATCH, DELETE

Non-Idempotent Method: POST - Making multiple POST requests will create multiple new resources, resulting in different states each time

What is Safe?

An HTTP method is safe if it doesn't alter the state of the server. Safe methods are typically used for retrieving data rather than modifying it:

Safe Method: GET (as it only retrieves data without changing the server state)

Non-Safe Methods: POST, PUT, PATCH, DELETE (as they alter the state by creating, updating, or deleting resources)