Lesson 36 of 158 – Postman PUT Request
36%

Postman PUT Request

A PUT request is used to update an existing resource on a server. In Postman, we can use PUT requests to test APIs that update complete records such as students, users, products, or courses.

Note: PUT is commonly used when a mobile application needs to send updated information for an existing record.

1. What is a PUT Request?

A PUT request is an HTTP request used to update an existing resource on a server.

For example:

PUT /students/10

This request can be used to update the student whose ID is 10.

2. PUT Request in Postman

Postman allows us to easily create and test PUT requests.

The basic process is:

  1. Select PUT
  2. Enter the API URL
  3. Open the Body section
  4. Enter updated data
  5. Click Send
  6. Check the response

3. Create a New PUT 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 PUT request.

4. Select PUT Method

Click the HTTP method dropdown and select PUT.

PUT

PUT tells the server that the client wants to update an existing resource.

5. Enter the API URL

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

Example:

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

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

6. PUT Request Needs a Body

A PUT request commonly sends the updated resource information in the request body.

Example:

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

7. Open the Body Section

After selecting PUT, click the Body tab in Postman.

The Body section is used to provide the updated data that should be sent to the server.

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 your API accepts JSON, select JSON from the format dropdown.

Example:

{
    "name": "Rahul Kumar",
    "course": "Python"
}

10. Enter Updated JSON Data

Enter the new values that you want to send to the API.

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

The API can use this data to update the existing student.

11. Identify the Resource

The API needs to know which record should be updated.

This can be done using an ID in the URL.

PUT 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 PUT Request

After entering the updated JSON data, click the Send button.

Postman sends the PUT request to the server.

PUT
 ↓
API URL
 ↓
Request Body
 ↓
Server

14. Server Receives PUT Data

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

A PHP REST API can decode the JSON data and use it to update the database.

PUT Request
      ↓
PHP API
      ↓
Read JSON
      ↓
Validate Data
      ↓
Update Database

15. PUT Data and MySQL

A PHP REST API can use the PUT data to update an existing MySQL record.

For example:

PUT JSON
   ↓
PHP API
   ↓
MySQL UPDATE
   ↓
Updated Student Record

16. Example Student Update

Suppose student ID 10 currently has the following information:

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

We can send a PUT request to update the course:

{
    "name": "Rahul Kumar",
    "course": "Python"
}

17. Successful PUT Response

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

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

The response informs the client that the update was completed.

18. Status Code 200 OK

A successful PUT request commonly returns:

200 OK

This indicates that the server successfully processed the update.

19. 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 whether the requested ID exists before updating.

20. Validation Error

The API should validate the updated data before changing the database.

For example, if the student name is required but is missing:

{
    "status": false,
    "message": "Name is required"
}

21. PUT and Complete Resource Update

PUT is commonly associated with replacing or updating the complete representation of an existing resource.

For example, an API may expect all important student fields in the request.

{
    "name": "Amit Kumar",
    "course": "Java",
    "mobile": "9876543210",
    "fee": 6000
}

22. PUT vs POST

POST PUT
Commonly used to create a resource Commonly used to update an existing resource
Usually sends new data Usually sends updated data
Example: Add student Example: Update student

23. PUT Request and React Native

React Native applications can use PUT requests when a user edits existing information.

Examples include:

  • Update student profile
  • Update user information
  • Edit product details
  • Update course information
  • Update account settings

24. PUT Request Mobile App Flow

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

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

25. Common PUT Request Mistakes

  • Wrong API URL
  • Wrong HTTP method
  • Missing record ID
  • Invalid JSON
  • Missing required fields
  • Incorrect Content-Type
  • Server not running
  • Database update error

26. Debugging a PUT Request

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

  1. Check the API URL.
  2. Confirm PUT is selected.
  3. Check the record ID.
  4. Open the Body section.
  5. Check JSON syntax.
  6. Check Content-Type.
  7. Check the PHP API.
  8. Check the database.

27. Complete PUT Request Flow

1. Open Postman
2. Create a request
3. Select PUT
4. Enter API URL
5. Add record ID
6. Open Body
7. Select raw
8. Select JSON
9. Enter updated data
10. Click Send
11. Check the response

28. Complete PUT Example

Method:

PUT

URL:

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

Body:

{
    "name": "Amit Kumar",
    "course": "Java",
    "mobile": "9876543210"
}

Click Send to update the student.

29. Example PUT Response

After successfully updating the student, the API might return:

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

The React Native application can use this response to refresh the displayed information.

30. Postman PUT Request Summary

A PUT request is commonly used to update an existing resource. In Postman, select PUT, enter the API URL with the resource identifier, provide the updated JSON data in the Body section, and click Send.

PUT
   ↓
Resource ID
   ↓
JSON Request Body
   ↓
PHP REST API
   ↓
Validation
   ↓
MySQL UPDATE
   ↓
JSON Response

📌 Key Points

  • PUT is commonly used to update an existing resource.
  • Postman can be used to test PUT APIs.
  • The resource ID identifies the record to update.
  • PUT commonly sends updated information in the request body.
  • JSON can be used for the PUT request body.
  • Content-Type can be set to application/json.
  • The API should validate the updated data.
  • The API should check whether the requested resource exists.
  • PHP can use PUT data to update MySQL records.
  • React Native applications can use PUT requests to update data.

🧠 Quick Quiz

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