Here are the common HTTP methods with examples

  • GET Retrieves data from a server.

Example: Fetch a list of users.

GET /users HTTP/1.1
Host: example.com
  • POST: Submits data to a server to create a new resource.

Example: Create a new user.

POST /users HTTP/1.1
Host: example.com
Content-Type: application/json

{
"name": "John Doe",
"email": "johndoe@example.com"
}
  • PUT: Updates an existing resource or creates it if it does not exist.

Example: Update user information.

PUT /users/1 HTTP/1.1
Host: example.com
Content-Type: application/json

{
"name": "John Doe",
"email": "john.doe@example.com"
}
  • DELETE: Deletes a resource from the server.

Example: Delete a user.

DELETE /users/1 HTTP/1.1
Host: example.com
  • PATCH: Partially updates an existing resource.

Example: Update the email of a user.

PATCH /users/1 HTTP/1.1
Host: example.com
Content-Type: application/json

{
"email": "newemail@example.com"
}
  • HEAD: Similar to GET but without the response body. Used to check if a resource exists or to retrieve metadata.

Example: Check if a user exists.

HEAD /users/1 HTTP/1.1
Host: example.com
  • OPTIONS: Describes the communication options for the target resource.

Example: Retrieve the supported HTTP methods for a resource.

OPTIONS /users HTTP/1.1
Host: example.com

These methods provide a fundamental framework for interacting with web servers and manipulating web resources.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top