Common HTTP Methods
By Łukasz Kallas
- Published on
Sharing
HTTP methods, also known as HTTP verbs, define the action to be performed on a given resource.
Common HTTP Methods
- GET
The GET method is used to retrieve data from a server. It is a read-only request that does not alter the state of the resource.
- Use Case: Fetching data from an API, such as retrieving user details or a list of products.
- Idempotent: Yes (multiple identical requests have the same effect as a single request).
- POST
The POST method is used to send data to a server to create a new resource. It often involves submitting form data or uploading a file.
- Use Case: Creating a new user account or posting a comment.
- Idempotent: No (repeated requests can result in multiple resource creations).
- PUT
The PUT method is used to update an existing resource or create a new resource if it does not exist. It replaces the entire resource with the new data provided.
- Use Case: Updating user information or replacing a document.
- Idempotent: Yes (multiple identical requests result in the same state).
- DELETE
The DELETE method is used to remove a resource from the server.
- Use Case: Deleting a user account or removing an item from a database.
- Idempotent: Yes (multiple identical requests have the same effect as a single request).
- PATCH
The PATCH method is used to apply partial modifications to a resource. Unlike PUT, it only updates the specified fields rather than replacing the entire resource.
- Use Case: Updating specific fields of a user profile, such as changing the email address.
- Idempotent: Yes (multiple identical requests result in the same state).