Now that Postman is installed, it is time to create our first API request. In this lesson, we will learn how to select an HTTP method, enter an API URL, send the request, and understand the response.
This is an important step because the same API request that we test in Postman can later be called from our React Native application.
An API request is a message sent by a client to a server asking it to perform an operation or return information.
Client
↓
API Request
↓
Server
↓
API Response
Postman acts as the client when we test an API.
Postman can behave like a client application and send HTTP requests to a REST API.
Postman
↓
HTTP Request
↓
REST API
↓
HTTP Response
This allows us to test the backend independently.
Open Postman and create a new HTTP request.
A request normally contains:
For our first request, we will keep the request simple.
The first step is to select the HTTP method.
For our first request, select:
GET
GET is commonly used to retrieve information from a server.
After selecting GET, enter the URL of the API endpoint.
For example:
https://example.com/api/students
The URL must point to an actual API endpoint for the request to return the expected API response.
When developing a PHP REST API locally, the URL may look like:
http://localhost/rest_api/api/students.php
The exact URL depends on your local PHP project folder and API file.
After selecting GET and entering the URL, click the Send button.
GET
+
API URL
↓
Send
↓
Server
↓
Response
Postman sends the HTTP request to the specified server.
When you click Send, Postman sends the request to the server. The server processes the request and returns a response.
Postman
↓
GET Request
↓
Server
↓
Process Request
↓
Response
↓
Postman
Postman displays the response returned by the server.
Important response information includes:
If the API request is successful, the server may return:
200 OK
For example, the response body could be:
{
"success": true,
"message": "API is working"
}
If the REST API returns JSON, Postman displays the JSON response in the response body.
{
"success": true,
"message": "Students found",
"data": []
}
JSON is commonly used for communication between REST APIs and mobile applications.
Always check the HTTP status code after sending an API request.
| Status | Meaning |
|---|---|
| 200 | Request succeeded |
| 201 | Resource created |
| 400 | Bad request |
| 401 | Unauthorized |
| 404 | Resource not found |
| 500 | Server error |
Postman also displays the time taken by the server to return the response.
Response time can be useful when investigating API performance.
Request
↓
Server Processing
↓
Response
↓
Response Time
The response headers contain additional information about the response.
For example:
Content-Type: application/json
This tells the client that the response body contains JSON.
A simple GET request usually does not require a request body.
GET /api/students
The API URL itself identifies the resource that we want to retrieve.
We can add an Accept header to indicate that we expect JSON.
Accept: application/json
In Postman, this can be added from the Headers section.
The Headers section allows you to add information to the request.
| Header | Example Value |
|---|---|
| Accept | application/json |
| Content-Type | application/json |
| Authorization | Bearer TOKEN |
Our first request can now look like:
GET /api/students
Accept: application/json
The server can return JSON data if the endpoint supports it.
Suppose our PHP API is located at:
http://localhost/rest_api/api/students.php
In Postman:
Suppose the PHP API contains:
header(
"Content-Type: application/json"
);
echo json_encode([
"success" => true,
"message" => "API is working"
]);
Postman should receive a JSON response similar to:
{
"success": true,
"message": "API is working"
}
If the URL is incorrect, the server may return a 404 response.
404 Not Found
Check:
If your local PHP server is not running, Postman will not be able to communicate with the local API.
Postman
↓
localhost
X
PHP Server Not Running
Start your local web server before testing a local PHP API.
If the API returns invalid JSON, Postman can help you identify that the response is not structured as expected.
A valid JSON response can look like:
{
"success": true,
"message": "Success"
}
Make sure JSON syntax is correct in your PHP API.
The request tested in Postman can later be implemented in React Native.
Postman:
GET
/api/students
Accept: application/json
↓
React Native:
fetch(
"https://example.com/api/students",
{
headers: {
"Accept":
"application/json"
}
}
);
If your first request does not work, check the following sequence:
1. Is the server running?
2. Is the URL correct?
3. Is the HTTP method correct?
4. Does the endpoint exist?
5. Are the headers correct?
6. What status code was returned?
7. What does the response body say?
Open Postman
↓
Create Request
↓
Select GET
↓
Enter API URL
↓
Add Headers if Required
↓
Click Send
↓
Server Processes Request
↓
Receive Response
↓
Check Status Code
↓
Check JSON Body
Let's imagine that our student API is available at:
http://localhost/rest_api/api/students.php
Configure Postman like this:
Method:
GET
URL:
http://localhost/rest_api/api/students.php
Header:
Accept: application/json
Click Send. If the API is working, Postman will display the response from the PHP server.
Creating the first Postman request is simple: select the HTTP method, enter the API URL, configure headers if required, send the request, and inspect the response.
POSTMAN
↓
GET
↓
API URL
↓
SEND
↓
PHP REST API
↓
JSON RESPONSE
↓
POSTMAN
Once you understand this basic process, you can use Postman to test POST, PUT, PATCH and DELETE requests as well as authentication, parameters and JSON request bodies.
Question: Which HTTP method should you commonly select in Postman when you want to retrieve data from an API?