Postman is a popular API testing tool used to send HTTP requests to APIs and inspect their responses. It is especially useful when developing and testing REST APIs before connecting them to a React Native mobile application.
In this course, we will use Postman to test our PHP and MySQL REST API before integrating it with React Native.
Postman is an application used for creating, sending, testing and debugging API requests.
For example, instead of opening a React Native application to test an API, you can send the request directly from Postman.
Postman
↓
REST API
↓
Response
Postman makes API development easier because you can test an API independently from the frontend or mobile application.
Postman works very well with REST APIs because REST APIs communicate using HTTP requests and responses.
Postman
↓
HTTP Request
↓
REST API
↓
HTTP Response
↓
Postman
You can inspect the complete communication in Postman.
Postman is not a replacement for React Native. Instead, it can be used to test the backend API before connecting that API to the mobile application.
First:
Postman → REST API
Then:
React Native → REST API
This makes it easier to identify whether a problem is in the API or in the mobile application.
Postman can be used to test many parts of a REST API.
| Feature | Example |
|---|---|
| GET | Get student list |
| POST | Create student |
| PUT | Update student |
| PATCH | Partially update student |
| DELETE | Delete student |
| Authentication | Login and token testing |
| Headers | Authorization and Content-Type |
A Postman request contains information such as the HTTP method, URL, headers, parameters and optional request body.
GET
https://example.com/api/students
When you click Send, Postman sends the request to the server.
After sending a request, Postman displays the response returned by the server.
The response can include:
200 OK
{
"success": true,
"message": "Students found"
}
Postman provides a method selector that allows you to choose the HTTP method for a request.
GET
POST
PUT
PATCH
DELETE
The selected method determines how the request is sent to the API.
A GET request is commonly used to retrieve information.
GET /api/students
Example response:
{
"success": true,
"data": [
{
"id": 1,
"name": "Rahul"
}
]
}
A POST request is commonly used to create new data.
POST /api/students
Example JSON body:
{
"name": "Rahul",
"email": "rahul@example.com",
"course": "React Native"
}
PUT is commonly used to update an existing resource.
PUT /api/students/10
Example body:
{
"name": "Rahul Kumar",
"email": "rahul@example.com",
"course": "React Native"
}
PATCH is commonly used when only part of an existing resource needs to be updated.
PATCH /api/students/10
Example:
{
"course": "Full Stack Development"
}
DELETE is commonly used to remove a resource.
DELETE /api/students/10
Example response:
{
"success": true,
"message": "Student deleted successfully"
}
Every API request requires a URL identifying the endpoint that should receive the request.
https://example.com/api/students
For a local PHP API, the URL may look like:
http://localhost/rest_api/api/students.php
After selecting the method and entering the API URL, the Send button sends the request to the server.
Select Method
↓
Enter URL
↓
Configure Request
↓
Click Send
↓
View Response
Headers provide additional information about an HTTP request.
Common API headers include:
Content-Type: application/json
Accept: application/json
Authorization: Bearer TOKEN
Headers are configured in the request's Headers section.
When an API expects JSON, Postman can be used to send a JSON request body.
{
"name": "Amit",
"email": "amit@example.com",
"course": "React Native"
}
For a JSON request, the Content-Type should normally indicate application/json.
Postman displays the HTTP status code returned by the server.
| Status | Example Meaning |
|---|---|
| 200 | Request succeeded |
| 201 | Resource created |
| 400 | Bad request |
| 401 | Authentication required or invalid |
| 404 | Resource not found |
| 500 | Server error |
The response body contains the data returned by the API.
{
"success": true,
"message": "Student found",
"data": {
"id": 1,
"name": "Rahul"
}
}
Postman displays the response body so that developers can inspect whether the API is returning the expected data.
Postman is particularly useful for testing a PHP REST API before connecting it to React Native.
Postman
↓
PHP REST API
↓
MySQL Database
↓
PHP Response
↓
Postman
This allows you to verify the backend independently.
Suppose our API endpoint is:
http://localhost/rest_api/api/students.php
We can select GET in Postman and click Send.
The API may return:
{
"success": true,
"data": [
{
"id": 1,
"name": "Rahul"
}
]
}
Postman can help identify problems in an API by showing the actual request and response.
For example, if an API returns 400 Bad Request, you can inspect:
Postman can also be used to test authenticated APIs.
For example:
Authorization:
Bearer YOUR_JWT_TOKEN
This becomes especially useful when we build JWT authentication for our React Native application.
Create API
↓
Test API in Postman
↓
Fix API Problems
↓
Test Again
↓
Connect React Native
↓
Test Mobile Application
Testing the backend first can make mobile application development easier.
For React Native developers, Postman is useful for testing the backend before writing the mobile API integration code.
For example:
First:
Postman → GET /api/students
Then:
React Native → GET /api/students
If the API works correctly in Postman, you can use the same endpoint from React Native.
Postman allows API requests to be organized into collections.
For example, a Student API collection can contain:
Collections make it easier to keep related API requests together.
Open Postman
↓
Create Request
↓
Select HTTP Method
↓
Enter API URL
↓
Add Headers
↓
Add Body if Required
↓
Click Send
↓
Check Status Code
↓
Check JSON Response
↓
Debug if Required
Suppose your PHP REST API is running at:
http://localhost/rest_api/api/students.php
In Postman:
If the API is working correctly, you may receive:
{
"success": true,
"message": "Students found",
"data": []
}
Postman is an important tool for REST API development. It allows us to test the backend independently before connecting it to a React Native application.
Postman
↓
HTTP Request
↓
PHP REST API
↓
MySQL
↓
JSON Response
↓
Postman
In the upcoming lessons, we will learn how to install and configure Postman and then create different API requests such as GET, POST, PUT, PATCH and DELETE.
Question: What is the main purpose of Postman in REST API development?