Lesson 45 of 158 – Postman CRUD Testing
45%

Postman CRUD Testing

CRUD stands for Create, Read, Update, and Delete. These four operations are the foundation of many REST APIs. Postman can be used to test each CRUD operation before connecting the API to a React Native mobile application.

Note: In this lesson, we will use a simple Student API example to understand how GET, POST, PUT, PATCH, and DELETE requests can be tested using Postman.

1. What is CRUD?

CRUD represents the four basic operations performed on data:

  • Create – Add new data
  • Read – Retrieve existing data
  • Update – Modify existing data
  • Delete – Remove data
Create
Read
Update
Delete

2. CRUD and HTTP Methods

REST APIs commonly map CRUD operations to HTTP methods.

CRUD HTTP Method
Create POST
Read GET
Update PUT / PATCH
Delete DELETE

3. Student API Example

Suppose our API manages student records.

Student
----------------
id
name
email
course
mobile

Postman can be used to test all CRUD operations for this student data.

4. API Base URL

Suppose our API is available at:

http://localhost/api

We can store this URL in a Postman environment variable.

{{base_url}}

5. Student API Endpoint

Suppose the student endpoint is:

{{base_url}}/students.php

This endpoint can be used for multiple CRUD operations depending on the HTTP method.

6. Create a Student with POST

The POST method can be used to create a new student.

POST
{{base_url}}/students.php

Select Body → raw → JSON in Postman.

7. POST Request Body

Send student information as JSON.

{
    "name": "Rahul Kumar",
    "email": "rahul@example.com",
    "course": "ADCA",
    "mobile": "9876543210"
}

Click Send to test the Create operation.

8. Check POST Response

After sending the POST request, check the response.

A successful response may contain:

{
    "success": true,
    "message": "Student created successfully"
}

Also check the HTTP status code returned by the API.

9. Read All Students

The GET method can be used to retrieve all students.

GET
{{base_url}}/students.php

Click Send in Postman to test the Read operation.

10. Check GET Response

The API may return an array of student records.

[
    {
        "id": 1,
        "name": "Rahul Kumar",
        "course": "ADCA"
    },
    {
        "id": 2,
        "name": "Amit Kumar",
        "course": "Tally"
    }
]

11. Read One Student

A single student can be retrieved using an ID.

GET
{{base_url}}/students.php?id=1

This request should return the student whose ID is 1.

12. Test Student Not Found

Try requesting an ID that does not exist.

GET
{{base_url}}/students.php?id=99999

Check whether the API returns an appropriate status code and error message.

13. Update a Student with PUT

The PUT method can be used to update an existing student.

PUT
{{base_url}}/students.php?id=1

The request should contain the updated student data.

14. PUT Request Body

{
    "name": "Rahul Kumar",
    "email": "rahulnew@example.com",
    "course": "Java Full Stack",
    "mobile": "9876543210"
}

Send the request and check whether the student information was updated.

15. Check PUT Response

A successful update may return a response such as:

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

Always verify the response and status code.

16. Update with PATCH

PATCH can be used when only part of a resource needs to be changed.

PATCH
{{base_url}}/students.php?id=1

For example, update only the course.

{
    "course": "Python"

17. Check PATCH Response

After sending a PATCH request, check whether the selected field was updated correctly.

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

18. Delete a Student

The DELETE method can be used to remove a student.

DELETE
{{base_url}}/students.php?id=1

Send the request after confirming that the API is designed to delete the specified record.

19. Check DELETE Response

A successful DELETE operation may return:

{
    "success": true,
    "message": "Student deleted successfully"
}

Verify the response and then use GET to confirm the expected data state.

20. Verify CRUD Operations

After testing each operation, verify the result using another request.

POST
  ↓
GET
  ↓
PUT
  ↓
GET
  ↓
DELETE
  ↓
GET

This helps confirm that the data changed as expected.

21. CRUD Testing Sequence

  1. Create a student.
  2. Read the student.
  3. Update the student.
  4. Read the student again.
  5. Delete the student.
  6. Try to read the deleted student.

This sequence provides a simple end-to-end CRUD test.

22. Test Validation During CRUD

CRUD testing should also include invalid data.

For example:

POST

{
    "name": "",
    "email": "",
    "course": ""
}

Check whether the API correctly validates required fields.

23. Test Duplicate Records

If an email or another field must be unique, try creating a duplicate record.

POST

{
    "name": "Rahul",
    "email": "rahul@example.com",
    "course": "ADCA"
}

Send the same request again and verify the API's duplicate-data behavior.

24. Test Invalid Student ID

Test update and delete operations with an invalid ID.

PUT
{{base_url}}/students.php?id=99999

DELETE
{{base_url}}/students.php?id=99999

The API should handle a missing student appropriately.

25. CRUD Testing Checklist

  • Test POST for creating data.
  • Test GET for reading data.
  • Test GET with an ID.
  • Test PUT for updating data.
  • Test PATCH for partial updates.
  • Test DELETE for removing data.
  • Check status codes.
  • Check response JSON.
  • Test invalid input.
  • Test missing records.
  • Verify changes after every operation.

26. Common CRUD Testing Mistakes

  • Testing only successful requests
  • Not checking response status codes
  • Not checking response JSON
  • Not testing invalid IDs
  • Not testing validation
  • Not verifying updated data
  • Not verifying deleted data
  • Using the wrong HTTP method

27. CRUD Testing with a Collection

All CRUD requests can be stored in a Postman collection.

Student Management API
│
├── Create Student
├── Get Students
├── Get Student
├── Update Student
├── Patch Student
└── Delete Student

This makes it easy to test the complete API repeatedly.

28. CRUD Testing Before React Native

It is useful to test the backend API in Postman before integrating it with the React Native application.

PHP + MySQL API
       ↓
Postman CRUD Testing
       ↓
Verify JSON Responses
       ↓
React Native Integration

This helps identify backend problems before mobile application development.

29. Complete CRUD Testing Workflow

CREATE
POST /students
      ↓
READ
GET /students
      ↓
UPDATE
PUT /students?id=1
      ↓
READ
GET /students?id=1
      ↓
DELETE
DELETE /students?id=1
      ↓
READ
GET /students?id=1

After each step, check the HTTP status code and response body.

30. Postman CRUD Testing Summary

Postman can be used to test the complete CRUD lifecycle of a REST API. Create data with POST, read data with GET, update data with PUT or PATCH, and delete data with DELETE. After each operation, verify the response and the resulting data.

POST
Create
  ↓
GET
Read
  ↓
PUT / PATCH
Update
  ↓
DELETE
Delete
  ↓
Verify Result

📌 Key Points

  • CRUD means Create, Read, Update, and Delete.
  • POST is commonly used for Create.
  • GET is used for Read.
  • PUT and PATCH are used for Update.
  • DELETE is used for Delete.
  • Postman can test the complete CRUD lifecycle.
  • Use JSON request bodies for APIs that expect JSON data.
  • Check HTTP status codes after every request.
  • Check the response JSON after every request.
  • Test invalid IDs and invalid input.
  • Verify data after create, update, and delete operations.
  • CRUD testing should be completed before integrating the API with React Native.

🧠 Quick Quiz

Question: Which HTTP method is commonly used to create a new resource in a REST API?