When to Use GET, POST, PUT, DELETE and PATCH in REST APIs

In this post, we’ll learn about the most commonly used HTTP methods that every QA engineer and even junior developers should understand when working with RESTful APIs. Each method has a specific purpose and use case. Although there are nine standard HTTP methods, we’ll focus on the five most relevant for everyday testing and development: GET, POST, PUT, DELETE, and PATCH.

Before we dive in, make sure to check out the previous article of this series 👉 Breaking Down an HTTP Request: What QA Engineers Need to Know

1. GET: Retrieving Data

The GET method is used to retrieve data from the server without making any changes to the data. It’s one of the most frequently used HTTP methods.

When to Use:
  • To fetch resources or data from an API.
  • To request specific information (e.g., user details or a blog post).
  • It is idempotent.

Example:

GET /users/123
Host: api.example.com
Authorization: Bearer <token>

This request fetches the details of the user with ID 123.

What Does “Idempotent” Mean?

An HTTP method is idempotent if calling it multiple times has the same effect as calling it once. In other words, no matter how many times you send the same request, the result on the server doesn’t change after the first time.

  • GET is idempotent because retrieving data doesn’t alter it.
  • DELETE is also idempotent because once a resource is deleted, trying again has no further impact.
  • PUT is idempotent too because sending the same full update multiple times yields the same final result.

This is different from POST and sometimes PATCH, which can create or change something each time they are called, even if the request is identical.

Now, let’s continue with the remaining methods:

2. POST: Creating New Data

The POST method is used to send data data to the server, typically to create a new resource.

When to Use:
  • When submitting data to create something new (e.g., a new user or a new order).
  • It is not idempotent

Example:

POST /users
Host: api.example.com
Content-Type: application/json
Authorization: Bearer <token>
{
  "name": "John Doe",
  "email": "johndoe@example.com"
}

This request creates a new user with the provided information in the JSON body.

3. PUT: Updating Data

The PUT method is used to update existing resource. It replaces the entire resource with the new data.

When to Use:
  • When replacing an entire resource with new content.
  • It is idempotent.

Example:

PUT /users/123
Host: api.example.com
Content-Type: application/json
Authorization: Bearer <token>
{
  "name": "John Doe R.",
  "email": "jhon_doer@example.com"
}

This request updates the user with ID 123, replacing their previous data.

4. DELETE: Removing Data

The DELETE method is used to remove a resource from the server.

When to Use:
  • When you need to delete a specific resource.
  • It is idempotent.

Example:

DELETE /users/123
Host: api.example.com
Authorization: Bearer <token>

This request deletes the user with ID 123.

5. PATCH: Partially Updating Data

The PATCH method is used for partially updating a resource, unlike PUT, which replaces the entire resource.

When to Use:
  • Partially updating an existing resource.
  • It is not always idempotent, depending on the server logic, repeated requests might have different results.

Example:

PATCH /users/123
Host: api.example.com
Content-Type: application/json
Authorization: Bearer <token>
{
  "email": "newemail@example.com"
}

This request only updates the email address of the user with ID 123.

How to Test HTTP Methods Effectively

As a QA engineer, understanding these methods allows you to test each API endpoint effectively. Here are some tips for testing each HTTP method:

  • GET: Ensure it retrieves the correct data without side effects.
  • POST: Test for valid and invalid inputs to ensure proper data creation.
  • PUT: Ensure it fully replaces the resource and handles missing/invalid data properly.
  • DELETE: Verify that it actually removes the resource and doesn’t affect other resources.
  • PATCH: Test partial updates and ensure the correct fields are modified without affecting unrelated data.

Final Thoughts

HTTP methods are foundational in RESTful API design and testing. By understanding the role of each method, QA engineers can ensure that APIs work as intended, handle edge cases effectively, and provide meaningful feedback to developers.

Next Up

Upcoming in this series 👉 We will explore the structure of API responses, including status codes, headers and body content, to ensure that your API behaves correctly.

👈 Back: Breaking Down an HTTP Request: What QA Engineers Need to Know