Lesson 37 of 158 – Postman PATCH Request
37%

Postman PATCH Request

A PATCH request is used to partially update an existing resource on a server. In Postman, we can use PATCH requests to test APIs that update only selected fields of an existing record.

Note: PATCH is useful when a mobile application needs to change only one or a few fields without sending the complete resource.

1. What is a PATCH Request?

A PATCH request is an HTTP request used to make a partial update to an existing resource.

For example:

PATCH /students/10

This request can update selected information of student ID 10.

2. PATCH Request in Postman

Postman provides an easy way to create and test PATCH requests.

The basic process is:

  1. Select PATCH
  2. Enter the API URL
  3. Open the Body section
  4. Enter the fields to update
  5. Click Send
  6. Check the response

3. Create a New PATCH Request

Open Postman and create a new HTTP request.

You will see the HTTP method dropdown, URL field, and Send button.

These controls are used to create and send the PATCH request.

4. Select PATCH Method

Click the HTTP method dropdown and select PATCH.

PATCH

PATCH tells the server that the client wants to make a partial update.

5. Enter the API URL

Enter the URL of the API that will update the existing resource.

Example:

http://localhost/api/students.php?id=10

The API can use the student ID to identify the record that should be updated.

6. PATCH Request Body

A PATCH request commonly contains only the fields that need to be changed.

For example, if we only want to change the course:

{
    "course": "Python"
}

There is no need to send every student field when the API supports partial updates.

7. Open the Body Section

After selecting PATCH, click the Body tab in Postman.

The Body section is used to enter the fields that should be updated.

8. Select raw Body

Select raw in the Body section.

The raw option allows you to directly enter the request data.

9. Select JSON Format

If the API accepts JSON, select JSON from the format dropdown.

Example:

{
    "mobile": "9876543210"
}

10. Enter Partial Update Data

Enter only the information that you want to change.

{
    "course": "Java"
}

The API can update only the course field of the selected student.

11. Identify the Resource

The API needs to know which record should be updated.

The resource ID can be included in the URL.

PATCH http://localhost/api/students.php?id=10

The ID 10 identifies the student to update.

12. Content-Type Header

When JSON data is sent, the request should indicate that the request body contains JSON.

Content-Type: application/json

Postman can add this header automatically when JSON is selected.

13. Send the PATCH Request

After entering the partial update data, click the Send button.

Postman sends the PATCH request to the API server.

PATCH
   ↓
API URL
   ↓
Request Body
   ↓
Server

14. Server Receives PATCH Data

The server receives the PATCH request and reads the request body.

A PHP REST API can decode the JSON data and update only the provided fields.

PATCH Request
      ↓
PHP API
      ↓
Read JSON
      ↓
Validate Data
      ↓
Partial Database Update

15. PATCH Data and MySQL

A PHP REST API can use PATCH data to update selected columns in a MySQL record.

For example:

PATCH JSON
    ↓
PHP API
    ↓
MySQL UPDATE
    ↓
Selected Field Updated

16. Example Student Update

Suppose student ID 10 has the following information:

{
    "name": "Rahul Kumar",
    "course": "ADCA",
    "mobile": "9876543210"
}

If we only want to change the course, we can send:

{
    "course": "Python"
}

The other student information can remain unchanged.

17. Updating Multiple Fields

PATCH can also update more than one selected field.

Example:

{
    "course": "Java",
    "mobile": "9123456789"
}

Only the specified fields are sent for the partial update.

18. Successful PATCH Response

After successfully updating the resource, the API can return a JSON response.

{
    "status": true,
    "message": "Student updated successfully"
}

The response informs the client that the update was completed.

19. Status Code 200 OK

A successful PATCH request commonly returns:

200 OK

This indicates that the server successfully processed the update.

20. Student Not Found

If the requested student does not exist, the API should return an appropriate error response.

For example:

{
    "status": false,
    "message": "Student not found"
}

The API should check the resource before performing the update.

21. PATCH Validation

The API should validate the fields received in the PATCH request.

For example, if a mobile number is being changed, the API can check whether the value has a valid format.

{
    "mobile": "9876543210"
}

Validation helps prevent invalid data from being stored.

22. PATCH vs PUT

PUT PATCH
Commonly used to update or replace a resource Commonly used for a partial update
May send the complete resource Usually sends only changed fields
Example: Update complete student Example: Update only student course

23. PATCH vs POST

POST PATCH
Commonly used to create a resource Commonly used to partially update a resource
Example: Add student Example: Change student course

24. PATCH Request and React Native

React Native applications can use PATCH requests when only part of a record needs to be changed.

Examples include:

  • Change user mobile number
  • Update student course
  • Change profile information
  • Update account settings
  • Change a product price

25. PATCH Request Mobile App Flow

React Native App
       ↓
PATCH Request
       ↓
PHP REST API
       ↓
Validate Data
       ↓
MySQL UPDATE
       ↓
JSON Response
       ↓
React Native App

Postman can be used to test the PATCH API before connecting it to the mobile application.

26. Common PATCH Request Mistakes

  • Wrong API URL
  • Wrong HTTP method
  • Missing resource ID
  • Invalid JSON
  • Invalid field name
  • Incorrect Content-Type
  • Server not running
  • Database update error

27. Debugging a PATCH Request

If a PATCH request does not work, check the following:

  1. Check the API URL.
  2. Confirm PATCH is selected.
  3. Check the resource ID.
  4. Check the Body section.
  5. Check JSON syntax.
  6. Check field names.
  7. Check Content-Type.
  8. Check the PHP API.
  9. Check the database.

28. Complete PATCH Request Flow

1. Open Postman
2. Create a request
3. Select PATCH
4. Enter API URL
5. Add resource ID
6. Open Body
7. Select raw
8. Select JSON
9. Enter fields to update
10. Click Send
11. Check the response

29. Complete PATCH Example

Method:

PATCH

URL:

http://localhost/api/students.php?id=10

Body:

{
    "course": "Java",
    "mobile": "9123456789"
}

Click Send to update only the selected student fields.

30. Postman PATCH Request Summary

A PATCH request is commonly used for partial updates. In Postman, select PATCH, enter the API URL with the resource identifier, provide only the fields that need to be changed in the JSON body, and click Send.

PATCH
   ↓
Resource ID
   ↓
Selected JSON Fields
   ↓
PHP REST API
   ↓
Validation
   ↓
MySQL UPDATE
   ↓
JSON Response

📌 Key Points

  • PATCH is commonly used for partial updates.
  • Postman can be used to test PATCH APIs.
  • The resource ID identifies the record to update.
  • PATCH usually sends only the fields that need to change.
  • JSON can be used for the PATCH request body.
  • Content-Type can be set to application/json.
  • The API should validate incoming fields.
  • The API should check whether the resource exists.
  • PHP can use PATCH data to update selected MySQL columns.
  • React Native applications can use PATCH requests for partial updates.

🧠 Quick Quiz

Question: Which HTTP method is commonly used to partially update an existing resource?