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.
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.
Postman allows us to easily create and test PUT requests.
The basic process is:
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.
Click the HTTP method dropdown and select PUT.
PUT
PUT tells the server that the client wants to update an existing resource.
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.
A PUT request commonly sends the updated resource information in the request body.
Example:
{
"name": "Rahul Kumar",
"course": "Python",
"mobile": "9876543210"
}
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.
Select raw in the Body section.
The raw option allows you to directly enter the request data.
If your API accepts JSON, select JSON from the format dropdown.
Example:
{
"name": "Rahul Kumar",
"course": "Python"
}
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.
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.
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.
After entering the updated JSON data, click the Send button.
Postman sends the PUT request to the server.
PUT
↓
API URL
↓
Request Body
↓
Server
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
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
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"
}
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.
A successful PUT request commonly returns:
200 OK
This indicates that the server successfully processed the update.
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.
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"
}
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
}
| 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 |
React Native applications can use PUT requests when a user edits existing information.
Examples include:
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.
If a PUT request does not work, check the following:
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
Method:
PUT
URL:
http://localhost/api/students.php?id=10
Body:
{
"name": "Amit Kumar",
"course": "Java",
"mobile": "9876543210"
}
Click Send to update the student.
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.
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
Question: Which HTTP method is commonly used to update an existing resource?