Types of Requests GET, POST, PUT, PATCH, DELETE

To connect with our server, we send different types of requests.

1. GET Request – Fetch Data from Server

  • The GET request is used to retrieve (fetch) information from a server.
  • This is the most commonly used request when an application needs to read data without making any changes to it.

πŸ“Œ Example Use Cases:
βœ… Fetching a user profile from a database.
βœ… Retrieving a list of posts from a blog.
βœ… Getting weather updates from an API.

πŸ“Œ Example Request:

This will fetch the data of a user with ID 123 from the server.

πŸ“Œ Example Response from Server:

2. POST Request – Add New Data to Server

  • The POST request is used when we want to send new data to the server and store it in a database.
  • Unlike GET, a POST request modifies the server’s data.

πŸ“Œ Example Use Cases:
βœ… Signing up a new user.
βœ… Adding a new blog post.
βœ… Submitting a contact form.

πŸ“Œ Example Request:

  • This will create a new user with the given details in the database.

πŸ“Œ Example Response from Server:

3. PUT Request – Update Entire Data

  • The PUT request is used to update an entire record in the server.
  • If a record exists, it gets updated; if not, a new record is created.
  • All fields must be included in the request, even if only one value is being changed.

πŸ“Œ Example Use Cases:
βœ… Updating user profile information.
βœ… Replacing old product details with new ones.

πŸ“Œ Example Request:

  • This will replace the entire user record in the database.

πŸ“Œ Example Response from Server:

4. PATCH Request – Update Specific Fields

  • The PATCH request is similar to PUT but only updates specific fields instead of replacing the entire record.
  • This is useful when only a few changes are needed instead of resending the entire dataset.

πŸ“Œ Example Use Cases:
βœ… Updating only the email of a user.
βœ… Changing only the price of a product.

πŸ“Œ Example Request:

  • This will only update the email of the user and keep other details unchanged.

πŸ“Œ Example Response from Server:

5. DELETE Request – Remove Data from Server

  • The DELETE request is used to remove a specific resource from the server.
  • Once deleted, the data cannot be retrieved unless the system has a backup.

πŸ“Œ Example Use Cases:
βœ… Deleting a user account permanently.
βœ… Removing a blog post from a website.
βœ… Deleting an order from a shopping cart.

πŸ“Œ Example Request:

  • This will delete the user with ID 123 from the server.

πŸ“Œ Example Response from Server:

Summary Table – Quick Comparison

Request TypePurposeExample Use Case
GETFetch data from serverGet user profile, retrieve blog posts
POSTAdd new data to serverCreate a new user, add a new post
PUTReplace entire dataUpdate all details of a user
PATCHUpdate specific fieldsChange only the email or password
DELETERemove data from serverDelete a comment, remove an order
Facebook
WhatsApp
Twitter
LinkedIn

Leave a Comment

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

Scroll to Top