A DELETE request is used to remove an existing resource from a server. In Postman, we can use DELETE requests to test APIs that remove records such as students, users, products, or courses.
A DELETE request is an HTTP request used to remove an existing resource from a server.
For example:
DELETE /students/10
This request can be used to delete the student whose ID is 10.
Postman provides an easy way to create and test DELETE 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 DELETE request.
Click the HTTP method dropdown and select DELETE.
DELETE
DELETE tells the server that the client wants to remove a resource.
Enter the URL of the API that will delete 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 deleted.
The API needs to know which resource should be deleted.
An ID can be provided as a query parameter.
http://localhost/api/students.php?id=10
Here, id=10 identifies the student that should be removed.
A DELETE request often does not require a request body when the resource can be identified through the URL.
DELETE http://localhost/api/students.php?id=10
The server can use the ID to identify the resource.
After selecting DELETE and entering the API URL, click the Send button.
Postman sends the DELETE request to the API server.
DELETE
↓
API URL
↓
Server
The server receives the DELETE request and identifies the resource.
A PHP REST API can use the resource ID to find the corresponding database record.
DELETE Request
↓
PHP API
↓
Find Resource
↓
Delete Record
A PHP REST API can use a DELETE request to remove a record from a MySQL database.
Conceptually:
DELETE Request
↓
PHP API
↓
MySQL DELETE
↓
Record Removed
Suppose our database contains a student with ID 15.
We can send the following request:
DELETE http://localhost/api/students.php?id=15
The API can use ID 15 to identify the student.
After successfully deleting the resource, the API can return a JSON response.
{
"status": true,
"message": "Student deleted successfully"
}
The response tells the client that the delete operation was completed.
A successful DELETE operation may return:
200 OK
The response body can contain additional information about the operation.
Another possible successful response for DELETE is:
204 No Content
This indicates that the request was successfully processed and the server does not return a response body.
If the requested resource does not exist, the API can return an appropriate error response.
{
"status": false,
"message": "Student not found"
}
The API should check whether the resource exists before deleting it.
If the requested resource cannot be found, the API may return:
404 Not Found
For example, this can happen when the requested student ID does not exist.
A DELETE API may require an ID to identify the resource.
For example, this URL does not contain an ID:
http://localhost/api/students.php
If the API requires an ID, it should return a validation error instead of deleting an unspecified record.
A properly designed DELETE endpoint should identify the requested resource and delete only that resource.
For example:
DELETE /students.php?id=10
The API should target the student with ID 10 rather than unrelated records.
Delete operations often require authentication and authorization.
For example, an API may require an access token before allowing a user to delete a record.
Authorization: Bearer YOUR_TOKEN
Authentication and authorization will be covered in later REST API lessons.
React Native applications can use DELETE requests when a user needs to remove an existing resource.
Examples include:
React Native App
↓
DELETE Request
↓
PHP REST API
↓
Check Resource
↓
MySQL DELETE
↓
JSON Response
↓
React Native App
Postman can be used to test the DELETE API before connecting it to the mobile application.
| GET | DELETE |
|---|---|
| Commonly used to retrieve data | Commonly used to remove data |
| Does not normally change the resource | Changes the server by removing a resource |
| Example: Get student | Example: Delete student |
| POST | DELETE |
|---|---|
| Commonly used to create a resource | Commonly used to remove a resource |
| Example: Add student | Example: Delete student |
| Method | Common Purpose |
|---|---|
| PUT | Update an existing resource |
| PATCH | Partially update an existing resource |
| DELETE | Remove an existing resource |
If a DELETE request does not work, check the following:
1. Open Postman
2. Create a request
3. Select DELETE
4. Enter API URL
5. Add resource ID
6. Add authentication if required
7. Click Send
8. Check the response
9. Verify the resource was removed
Method:
DELETE
URL:
http://localhost/api/students.php?id=10
Action:
Click Send to send the DELETE request to the API.
The API can find student ID 10 and remove the corresponding record.
After successfully deleting the student, the API might return:
{
"status": true,
"message": "Student deleted successfully",
"student_id": 10
}
The React Native application can use this response to remove the student from the displayed list.
A DELETE request is commonly used to remove an existing resource. In Postman, select DELETE, enter the API URL with the resource identifier, click Send, and inspect the response.
DELETE
↓
Resource ID
↓
PHP REST API
↓
Check Resource
↓
MySQL DELETE
↓
JSON Response
Question: Which HTTP method is commonly used to remove an existing resource?